multipasta
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -293,2 +293,14 @@ "use strict"; | ||
let ended = false; | ||
function addError(err) { | ||
if (error === null) { | ||
error = { | ||
_tag: "MultipartPullError", | ||
errors: [err] | ||
}; | ||
hasData = true; | ||
} else { | ||
; | ||
error.errors.push(err); | ||
} | ||
} | ||
const parser = make({ | ||
@@ -317,21 +329,14 @@ ...config, | ||
}, | ||
onError(error_) { | ||
if (error === null) { | ||
error = { | ||
_tag: "MultipartPullError", | ||
errors: [error_] | ||
}; | ||
hasData = true; | ||
} else { | ||
; | ||
error.errors.push(error_); | ||
} | ||
}, | ||
onError: addError, | ||
onDone() {} | ||
}); | ||
function pull(cb) { | ||
config.pull(function (chunk) { | ||
config.pull(function (err, chunk) { | ||
if (chunk === null) { | ||
parser.end(); | ||
ended = true; | ||
} else if (err !== null) { | ||
parser.end(); | ||
ended = true; | ||
addError(err); | ||
} else if (!ended) { | ||
@@ -338,0 +343,0 @@ for (let i = 0; i < chunk.length; i++) { |
@@ -55,4 +55,4 @@ import type * as HeadersParser from "./HeadersParser.js"; | ||
export type Part = File | Field; | ||
export type PullConfig = { | ||
readonly pull: (cb: (chunk: ReadonlyArray<Uint8Array> | null) => void) => void; | ||
export type PullConfig<E> = { | ||
readonly pull: (cb: (err: E | null, chunk: ReadonlyArray<Uint8Array> | null) => void) => void; | ||
readonly headers: Record<string, string>; | ||
@@ -65,7 +65,7 @@ readonly isFile?: (info: PartInfo) => boolean; | ||
}; | ||
export interface MultipartPullError { | ||
export interface MultipartPullError<E> { | ||
readonly _tag: "MultipartPullError"; | ||
readonly errors: ReadonlyArray<MultipartError>; | ||
readonly errors: ReadonlyArray<MultipartError | E>; | ||
} | ||
export declare const makePull: (config: PullConfig) => (cb: (err: MultipartPullError | null, part: readonly Part[] | null) => void) => void; | ||
export declare const makePull: <E = never>(config: PullConfig<E>) => (cb: (err: MultipartPullError<E> | null, part: readonly Part[] | null) => void) => void; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -10,3 +10,3 @@ import { Config, Field, File, MultipartPullError, Part, PartInfo, PullConfig } from "../index.js"; | ||
export declare function isField(part: Part): part is Field; | ||
export declare function makePull(config: PullConfig): (cb: (err: MultipartPullError | null, part: ReadonlyArray<Part> | null) => void) => void; | ||
export declare function makePull<E = never>(config: PullConfig<E>): (cb: (err: MultipartPullError<E> | null, part: ReadonlyArray<Part> | null) => void) => void; | ||
//# sourceMappingURL=multipart.d.ts.map |
@@ -257,2 +257,14 @@ import * as CT from "./contentType.js"; | ||
let ended = false; | ||
function addError(err) { | ||
if (error === null) { | ||
error = { | ||
_tag: "MultipartPullError", | ||
errors: [err] | ||
}; | ||
hasData = true; | ||
} else { | ||
; | ||
error.errors.push(err); | ||
} | ||
} | ||
const parser = make({ | ||
@@ -281,21 +293,14 @@ ...config, | ||
}, | ||
onError(error_) { | ||
if (error === null) { | ||
error = { | ||
_tag: "MultipartPullError", | ||
errors: [error_] | ||
}; | ||
hasData = true; | ||
} else { | ||
; | ||
error.errors.push(error_); | ||
} | ||
}, | ||
onError: addError, | ||
onDone() {} | ||
}); | ||
function pull(cb) { | ||
config.pull(function (chunk) { | ||
config.pull(function (err, chunk) { | ||
if (chunk === null) { | ||
parser.end(); | ||
ended = true; | ||
} else if (err !== null) { | ||
parser.end(); | ||
ended = true; | ||
addError(err); | ||
} else if (!ended) { | ||
@@ -302,0 +307,0 @@ for (let i = 0; i < chunk.length; i++) { |
{ | ||
"name": "multipasta", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -79,4 +79,6 @@ import * as internal from "./internal/multipart.js" | ||
export type PullConfig = { | ||
readonly pull: (cb: (chunk: ReadonlyArray<Uint8Array> | null) => void) => void | ||
export type PullConfig<E> = { | ||
readonly pull: ( | ||
cb: (err: E | null, chunk: ReadonlyArray<Uint8Array> | null) => void, | ||
) => void | ||
readonly headers: Record<string, string> | ||
@@ -90,11 +92,11 @@ readonly isFile?: (info: PartInfo) => boolean | ||
export interface MultipartPullError { | ||
export interface MultipartPullError<E> { | ||
readonly _tag: "MultipartPullError" | ||
readonly errors: ReadonlyArray<MultipartError> | ||
readonly errors: ReadonlyArray<MultipartError | E> | ||
} | ||
export const makePull: ( | ||
config: PullConfig, | ||
export const makePull: <E = never>( | ||
config: PullConfig<E>, | ||
) => ( | ||
cb: (err: MultipartPullError | null, part: readonly Part[] | null) => void, | ||
cb: (err: MultipartPullError<E> | null, part: readonly Part[] | null) => void, | ||
) => void = internal.makePull |
@@ -300,8 +300,17 @@ import { | ||
export function makePull(config: PullConfig) { | ||
export function makePull<E = never>(config: PullConfig<E>) { | ||
let partBuffer: Array<Part> = [] | ||
let error: MultipartPullError | null = null | ||
let error: MultipartPullError<E> | null = null | ||
let hasData = false | ||
let ended = false | ||
function addError(err: E | MultipartError) { | ||
if (error === null) { | ||
error = { _tag: "MultipartPullError", errors: [err] } | ||
hasData = true | ||
} else { | ||
;(error.errors as any).push(err) | ||
} | ||
} | ||
const parser = make({ | ||
@@ -326,10 +335,3 @@ ...config, | ||
}, | ||
onError(error_) { | ||
if (error === null) { | ||
error = { _tag: "MultipartPullError", errors: [error_] } | ||
hasData = true | ||
} else { | ||
;(error.errors as any).push(error_) | ||
} | ||
}, | ||
onError: addError, | ||
onDone() {}, | ||
@@ -339,6 +341,10 @@ }) | ||
function pull(cb: () => void) { | ||
config.pull(function (chunk) { | ||
config.pull(function (err, chunk) { | ||
if (chunk === null) { | ||
parser.end() | ||
ended = true | ||
} else if (err !== null) { | ||
parser.end() | ||
ended = true | ||
addError(err) | ||
} else if (!ended) { | ||
@@ -357,3 +363,3 @@ for (let i = 0; i < chunk.length; i++) { | ||
cb: ( | ||
err: MultipartPullError | null, | ||
err: MultipartPullError<E> | null, | ||
part: ReadonlyArray<Part> | null, | ||
@@ -360,0 +366,0 @@ ) => void, |
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
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
149316
2510