Skip to content

Commit b3f8475

Browse files
committed
1 parent 4a82a8f commit b3f8475

File tree

14 files changed

+189
-902
lines changed

14 files changed

+189
-902
lines changed

node_modules/.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@
9696
/minipass-pipeline/node_modules/*
9797
!/minipass-pipeline/node_modules/minipass
9898
!/minipass-sized
99-
!/minipass-sized/node_modules/
100-
/minipass-sized/node_modules/*
101-
!/minipass-sized/node_modules/minipass
10299
!/minipass
103100
!/minizlib
104101
!/ms

node_modules/minipass-fetch/lib/body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
const { Minipass } = require('minipass')
3-
const MinipassSized = require('minipass-sized')
3+
const { MinipassSized } = require('minipass-sized')
44

55
const Blob = require('./blob.js')
66
const { BUFFER } = Blob

node_modules/minipass-fetch/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minipass-fetch",
3-
"version": "5.0.0",
3+
"version": "5.0.1",
44
"description": "An implementation of window.fetch in Node.js using Minipass streams",
55
"license": "MIT",
66
"main": "lib/index.js",
@@ -38,7 +38,7 @@
3838
},
3939
"dependencies": {
4040
"minipass": "^7.0.3",
41-
"minipass-sized": "^1.0.3",
41+
"minipass-sized": "^2.0.0",
4242
"minizlib": "^3.0.1"
4343
},
4444
"optionalDependencies": {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.MinipassSized = exports.SizeError = void 0;
4+
const minipass_1 = require("minipass");
5+
const isBufferEncoding = (enc) => typeof enc === 'string';
6+
class SizeError extends Error {
7+
expect;
8+
found;
9+
code = 'EBADSIZE';
10+
constructor(found, expect, from) {
11+
super(`Bad data size: expected ${expect} bytes, but got ${found}`);
12+
this.expect = expect;
13+
this.found = found;
14+
Error.captureStackTrace(this, from ?? this.constructor);
15+
}
16+
get name() {
17+
return 'SizeError';
18+
}
19+
}
20+
exports.SizeError = SizeError;
21+
class MinipassSized extends minipass_1.Minipass {
22+
found = 0;
23+
expect;
24+
constructor(options) {
25+
const size = options?.size;
26+
if (typeof size !== 'number' ||
27+
size > Number.MAX_SAFE_INTEGER ||
28+
isNaN(size) ||
29+
size < 0 ||
30+
!isFinite(size) ||
31+
size !== Math.floor(size)) {
32+
throw new Error('invalid expected size: ' + size);
33+
}
34+
//@ts-ignore
35+
super(options);
36+
if (options.objectMode) {
37+
throw new TypeError(`${this.constructor.name} streams only work with string and buffer data`);
38+
}
39+
this.expect = size;
40+
}
41+
write(chunk, encoding, cb) {
42+
const buffer = Buffer.isBuffer(chunk) ? chunk
43+
: typeof chunk === 'string' ?
44+
Buffer.from(chunk, isBufferEncoding(encoding) ? encoding : 'utf8')
45+
: chunk;
46+
if (typeof encoding === 'function') {
47+
cb = encoding;
48+
encoding = null;
49+
}
50+
if (!Buffer.isBuffer(buffer)) {
51+
this.emit('error', new TypeError(`${this.constructor.name} streams only work with string and buffer data`));
52+
return false;
53+
}
54+
this.found += buffer.length;
55+
if (this.found > this.expect)
56+
this.emit('error', new SizeError(this.found, this.expect));
57+
return super.write(chunk, encoding, cb);
58+
}
59+
emit(ev, ...args) {
60+
if (ev === 'end') {
61+
if (this.found !== this.expect) {
62+
this.emit('error', new SizeError(this.found, this.expect, this.emit));
63+
}
64+
}
65+
return super.emit(ev, ...args);
66+
}
67+
}
68+
exports.MinipassSized = MinipassSized;
69+
//# sourceMappingURL=index.js.map
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Minipass } from 'minipass';
2+
const isBufferEncoding = (enc) => typeof enc === 'string';
3+
export class SizeError extends Error {
4+
expect;
5+
found;
6+
code = 'EBADSIZE';
7+
constructor(found, expect, from) {
8+
super(`Bad data size: expected ${expect} bytes, but got ${found}`);
9+
this.expect = expect;
10+
this.found = found;
11+
Error.captureStackTrace(this, from ?? this.constructor);
12+
}
13+
get name() {
14+
return 'SizeError';
15+
}
16+
}
17+
export class MinipassSized extends Minipass {
18+
found = 0;
19+
expect;
20+
constructor(options) {
21+
const size = options?.size;
22+
if (typeof size !== 'number' ||
23+
size > Number.MAX_SAFE_INTEGER ||
24+
isNaN(size) ||
25+
size < 0 ||
26+
!isFinite(size) ||
27+
size !== Math.floor(size)) {
28+
throw new Error('invalid expected size: ' + size);
29+
}
30+
//@ts-ignore
31+
super(options);
32+
if (options.objectMode) {
33+
throw new TypeError(`${this.constructor.name} streams only work with string and buffer data`);
34+
}
35+
this.expect = size;
36+
}
37+
write(chunk, encoding, cb) {
38+
const buffer = Buffer.isBuffer(chunk) ? chunk
39+
: typeof chunk === 'string' ?
40+
Buffer.from(chunk, isBufferEncoding(encoding) ? encoding : 'utf8')
41+
: chunk;
42+
if (typeof encoding === 'function') {
43+
cb = encoding;
44+
encoding = null;
45+
}
46+
if (!Buffer.isBuffer(buffer)) {
47+
this.emit('error', new TypeError(`${this.constructor.name} streams only work with string and buffer data`));
48+
return false;
49+
}
50+
this.found += buffer.length;
51+
if (this.found > this.expect)
52+
this.emit('error', new SizeError(this.found, this.expect));
53+
return super.write(chunk, encoding, cb);
54+
}
55+
emit(ev, ...args) {
56+
if (ev === 'end') {
57+
if (this.found !== this.expect) {
58+
this.emit('error', new SizeError(this.found, this.expect, this.emit));
59+
}
60+
}
61+
return super.emit(ev, ...args);
62+
}
63+
}
64+
//# sourceMappingURL=index.js.map
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

node_modules/minipass-sized/index.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

node_modules/minipass-sized/node_modules/minipass/LICENSE

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)