multipasta
Advanced tools
Comparing version 0.1.17 to 0.1.18
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.MultipastaStream = exports.FileStream = void 0; | ||
exports.MultipastaStream = exports.FileStream = exports.EagerMultipastaStream = void 0; | ||
Object.defineProperty(exports, "decodeField", { | ||
@@ -14,3 +14,3 @@ enumerable: true, | ||
}); | ||
exports.make = void 0; | ||
exports.makeEager = exports.make = void 0; | ||
var MP = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./index.js")); | ||
@@ -104,4 +104,50 @@ var _nodeStream = /*#__PURE__*/require("node:stream"); | ||
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 { | ||
@@ -108,0 +154,0 @@ info; |
@@ -45,3 +45,11 @@ /// <reference types="node" resolution-mode="require"/> | ||
} | ||
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 { | ||
@@ -48,0 +56,0 @@ readonly info: MP.PartInfo; |
@@ -64,3 +64,47 @@ import * as MP from "./index.js"; | ||
} | ||
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 { | ||
@@ -67,0 +111,0 @@ info; |
{ | ||
"name": "multipasta", | ||
"version": "0.1.17", | ||
"version": "0.1.18", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -106,5 +106,56 @@ /// <reference types="node" /> | ||
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 { | ||
@@ -111,0 +162,0 @@ readonly _tag = "File" |
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
192326
3219