multipasta
Advanced tools
Comparing version 0.1.18 to 0.1.19
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.MultipastaStream = exports.FileStream = exports.EagerMultipastaStream = void 0; | ||
exports.MultipastaStream = exports.FileStream = void 0; | ||
Object.defineProperty(exports, "decodeField", { | ||
@@ -14,3 +14,3 @@ enumerable: true, | ||
}); | ||
exports.makeEager = exports.make = void 0; | ||
exports.make = void 0; | ||
var MP = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./index.js")); | ||
@@ -63,4 +63,3 @@ var _nodeStream = /*#__PURE__*/require("node:stream"); | ||
onFile: info => { | ||
const file = new FileStream(info); | ||
file.on("resume", this._resume.bind(this)); | ||
const file = new FileStream(info, this); | ||
this.push(file); | ||
@@ -86,4 +85,5 @@ this.emit("file", file); | ||
if (this._writeCallback !== undefined) { | ||
this._writeCallback(); | ||
const callback = this._writeCallback; | ||
this._writeCallback = undefined; | ||
callback(); | ||
} | ||
@@ -106,62 +106,22 @@ } | ||
exports.MultipastaStream = MultipastaStream; | ||
class EagerMultipastaStream extends _nodeStream.Duplex { | ||
_parser; | ||
constructor(config) { | ||
super({ | ||
readableObjectMode: true | ||
}); | ||
this._parser = MP.make({ | ||
...config, | ||
onField: (info, value) => { | ||
const field = { | ||
_tag: "Field", | ||
info, | ||
value | ||
}; | ||
this.push(field); | ||
this.emit("field", field); | ||
}, | ||
onFile: info => { | ||
const file = new FileStream(info); | ||
this.push(file); | ||
this.emit("file", file); | ||
return chunk => { | ||
file.push(chunk); | ||
}; | ||
}, | ||
onError: error => { | ||
this.emit("error", error); | ||
}, | ||
onDone: () => { | ||
this.push(null); | ||
} | ||
}); | ||
} | ||
_read(_size) {} | ||
_write(chunk, encoding, callback) { | ||
this._parser.write(chunk instanceof Uint8Array ? chunk : Buffer.from(chunk, encoding)); | ||
callback(); | ||
} | ||
_final(callback) { | ||
this._parser.end(); | ||
callback(); | ||
} | ||
} | ||
exports.EagerMultipastaStream = EagerMultipastaStream; | ||
const make = config => new MultipastaStream(config); | ||
exports.make = make; | ||
const makeEager = config => new EagerMultipastaStream(config); | ||
exports.makeEager = makeEager; | ||
class FileStream extends _nodeStream.Readable { | ||
info; | ||
_parent; | ||
_tag = "File"; | ||
filename; | ||
constructor(info) { | ||
constructor(info, _parent) { | ||
super(); | ||
this.info = info; | ||
this._parent = _parent; | ||
this.filename = info.filename; | ||
} | ||
_read(_size) {} | ||
_read(_size) { | ||
if (this._parent._canWrite === false) { | ||
this._parent._resume(); | ||
} | ||
} | ||
} | ||
exports.FileStream = FileStream; | ||
//# sourceMappingURL=node.js.map |
@@ -16,2 +16,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
export interface MultipastaStream extends Duplex { | ||
[Symbol.asyncIterator](): AsyncIterableIterator<Part>; | ||
on(event: "field", listener: (field: Field) => void): this; | ||
@@ -38,3 +39,3 @@ on(event: "file", listener: (file: FileStream) => void): this; | ||
private _parser; | ||
private _canWrite; | ||
_canWrite: boolean; | ||
private _writeCallback; | ||
@@ -47,18 +48,11 @@ constructor(config: NodeConfig); | ||
} | ||
export declare class EagerMultipastaStream extends Duplex { | ||
private _parser; | ||
constructor(config: NodeConfig); | ||
_read(_size: number): void; | ||
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null | undefined) => void): void; | ||
_final(callback: (error?: Error | null | undefined) => void): void; | ||
} | ||
export declare const make: (config: NodeConfig) => MultipastaStream; | ||
export declare const makeEager: (config: NodeConfig) => EagerMultipastaStream; | ||
export declare class FileStream extends Readable { | ||
readonly info: MP.PartInfo; | ||
private _parent; | ||
readonly _tag = "File"; | ||
readonly filename: string; | ||
constructor(info: MP.PartInfo); | ||
constructor(info: MP.PartInfo, _parent: MultipastaStream); | ||
_read(_size: number): void; | ||
} | ||
//# sourceMappingURL=node.d.ts.map |
@@ -24,4 +24,3 @@ import * as MP from "./index.js"; | ||
onFile: info => { | ||
const file = new FileStream(info); | ||
file.on("resume", this._resume.bind(this)); | ||
const file = new FileStream(info, this); | ||
this.push(file); | ||
@@ -47,4 +46,5 @@ this.emit("file", file); | ||
if (this._writeCallback !== undefined) { | ||
this._writeCallback(); | ||
const callback = this._writeCallback; | ||
this._writeCallback = undefined; | ||
callback(); | ||
} | ||
@@ -66,58 +66,20 @@ } | ||
} | ||
export class EagerMultipastaStream extends Duplex { | ||
_parser; | ||
constructor(config) { | ||
super({ | ||
readableObjectMode: true | ||
}); | ||
this._parser = MP.make({ | ||
...config, | ||
onField: (info, value) => { | ||
const field = { | ||
_tag: "Field", | ||
info, | ||
value | ||
}; | ||
this.push(field); | ||
this.emit("field", field); | ||
}, | ||
onFile: info => { | ||
const file = new FileStream(info); | ||
this.push(file); | ||
this.emit("file", file); | ||
return chunk => { | ||
file.push(chunk); | ||
}; | ||
}, | ||
onError: error => { | ||
this.emit("error", error); | ||
}, | ||
onDone: () => { | ||
this.push(null); | ||
} | ||
}); | ||
} | ||
_read(_size) {} | ||
_write(chunk, encoding, callback) { | ||
this._parser.write(chunk instanceof Uint8Array ? chunk : Buffer.from(chunk, encoding)); | ||
callback(); | ||
} | ||
_final(callback) { | ||
this._parser.end(); | ||
callback(); | ||
} | ||
} | ||
export const make = config => new MultipastaStream(config); | ||
export const makeEager = config => new EagerMultipastaStream(config); | ||
export class FileStream extends Readable { | ||
info; | ||
_parent; | ||
_tag = "File"; | ||
filename; | ||
constructor(info) { | ||
constructor(info, _parent) { | ||
super(); | ||
this.info = info; | ||
this._parent = _parent; | ||
this.filename = info.filename; | ||
} | ||
_read(_size) {} | ||
_read(_size) { | ||
if (this._parent._canWrite === false) { | ||
this._parent._resume(); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=node.js.map |
{ | ||
"name": "multipasta", | ||
"version": "0.1.18", | ||
"version": "0.1.19", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -18,2 +18,4 @@ /// <reference types="node" /> | ||
export interface MultipastaStream extends Duplex { | ||
[Symbol.asyncIterator](): AsyncIterableIterator<Part> | ||
on(event: "field", listener: (field: Field) => void): this | ||
@@ -43,3 +45,3 @@ on(event: "file", listener: (file: FileStream) => void): this | ||
private _parser: MP.Parser | ||
private _canWrite = true | ||
_canWrite = true | ||
private _writeCallback: (() => void) | undefined | ||
@@ -57,4 +59,3 @@ | ||
onFile: info => { | ||
const file = new FileStream(info) | ||
file.on("resume", this._resume.bind(this)) | ||
const file = new FileStream(info, this) | ||
this.push(file) | ||
@@ -81,4 +82,5 @@ this.emit("file", file) | ||
if (this._writeCallback !== undefined) { | ||
this._writeCallback() | ||
const callback = this._writeCallback | ||
this._writeCallback = undefined | ||
callback() | ||
} | ||
@@ -110,64 +112,20 @@ } | ||
export class EagerMultipastaStream extends Duplex { | ||
private _parser: MP.Parser | ||
constructor(config: NodeConfig) { | ||
super({ readableObjectMode: true }) | ||
this._parser = MP.make({ | ||
...(config as any), | ||
onField: (info, value) => { | ||
const field: Field = { _tag: "Field", info, value } | ||
this.push(field) | ||
this.emit("field", field) | ||
}, | ||
onFile: info => { | ||
const file = new FileStream(info) | ||
this.push(file) | ||
this.emit("file", file) | ||
return chunk => { | ||
file.push(chunk) | ||
} | ||
}, | ||
onError: error => { | ||
this.emit("error", error) | ||
}, | ||
onDone: () => { | ||
this.push(null) | ||
}, | ||
}) | ||
} | ||
_read(_size: number) {} | ||
_write( | ||
chunk: any, | ||
encoding: BufferEncoding, | ||
callback: (error?: Error | null | undefined) => void, | ||
): void { | ||
this._parser.write( | ||
chunk instanceof Uint8Array ? chunk : Buffer.from(chunk, encoding), | ||
) | ||
callback() | ||
} | ||
_final(callback: (error?: Error | null | undefined) => void): void { | ||
this._parser.end() | ||
callback() | ||
} | ||
} | ||
export const make = (config: NodeConfig): MultipastaStream => | ||
new MultipastaStream(config) | ||
export const makeEager = (config: NodeConfig): EagerMultipastaStream => | ||
new EagerMultipastaStream(config) | ||
export class FileStream extends Readable { | ||
readonly _tag = "File" | ||
readonly filename: string | ||
constructor(readonly info: MP.PartInfo) { | ||
constructor( | ||
readonly info: MP.PartInfo, | ||
private _parent: MultipastaStream, | ||
) { | ||
super() | ||
this.filename = info.filename! | ||
} | ||
_read(_size: number) {} | ||
_read(_size: number) { | ||
if (this._parent._canWrite === false) { | ||
this._parent._resume() | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
186432
3098