Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multipasta

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multipasta - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

5

dist/cjs/index.js

@@ -6,3 +6,3 @@ "use strict";

});
exports.makePull = exports.make = exports.isFile = exports.isField = exports.defaultIsFile = exports.decodeField = void 0;
exports.make = exports.defaultIsFile = exports.decodeField = void 0;
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/multipart.js"));

@@ -37,5 +37,2 @@ function _getRequireWildcardCache(e) {

const decodeField = exports.decodeField = internal.decodeField;
const isFile = exports.isFile = internal.isFile;
const isField = exports.isField = internal.isField;
const makePull = exports.makePull = internal.makePull;
//# sourceMappingURL=index.js.map

@@ -8,6 +8,3 @@ "use strict";

exports.defaultIsFile = defaultIsFile;
exports.isField = isField;
exports.isFile = isFile;
exports.make = make;
exports.makePull = makePull;
var CT = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./contentType.js"));

@@ -257,114 +254,2 @@ var HP = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./headers.js"));

}
function isFile(part) {
return part._tag === "File";
}
function isField(part) {
return part._tag === "Field";
}
class FileImpl {
info;
pull;
_tag = "File";
filename;
constructor(info, pull) {
this.info = info;
this.pull = pull;
this.filename = info.filename;
}
buffer = [];
hasData = false;
finished = false;
read(cb) {
if (this.hasData) {
const buf = this.buffer;
this.buffer = [];
this.hasData = false;
cb(buf);
if (this.finished) {
cb(null);
}
} else if (this.finished) {
cb(null);
} else {
this.pull(() => this.read(cb));
}
}
}
function noop() {}
function makePull(config) {
let partBuffer = [];
let error = null;
let hasData = false;
let ended = false;
function addError(err) {
if (error === null) {
error = {
_tag: "MultipartPullError",
errors: [err]
};
hasData = true;
} else {
;
error.errors.push(err);
}
}
const parser = make({
...config,
onField(info, value) {
partBuffer.push({
_tag: "Field",
info,
value
});
hasData = true;
},
onFile(info) {
const file = new FileImpl(info, pull);
partBuffer.push(file);
hasData = true;
return function (chunk) {
if (chunk === null) {
file.finished = true;
} else {
file.buffer.push(chunk);
file.hasData = true;
}
};
},
onError: addError,
onDone() {}
});
function pull(cb) {
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) {
for (let i = 0; i < chunk.length; i++) {
parser.write(chunk[i]);
}
}
cb();
});
}
return function loop(cb) {
if (hasData) {
const result = partBuffer;
partBuffer = [];
hasData = false;
cb(error, result);
pull(noop);
} else if (ended) {
cb(error, null);
} else {
pull(function () {
loop(cb);
});
}
};
}
//# sourceMappingURL=multipart.js.map

@@ -45,24 +45,2 @@ import type * as HeadersParser from "./HeadersParser.js";

export declare const decodeField: (info: PartInfo, value: Uint8Array) => string;
export interface File {
readonly _tag: "File";
readonly filename: string;
readonly info: PartInfo;
readonly read: (cb: (chunk: ReadonlyArray<Uint8Array> | null) => void) => void;
}
export interface Field {
readonly _tag: "Field";
readonly info: PartInfo;
readonly value: Uint8Array;
}
export declare const isFile: (part: Part) => part is File;
export declare const isField: (part: Part) => part is Field;
export type Part = File | Field;
export type PullConfig<E> = BaseConfig & {
readonly pull: (cb: (err: E | null, chunk: ReadonlyArray<Uint8Array> | null) => void) => void;
};
export interface MultipartPullError<E> {
readonly _tag: "MultipartPullError";
readonly errors: ReadonlyArray<MultipartError | E>;
}
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

@@ -1,2 +0,2 @@

import { Config, Field, File, MultipartPullError, Part, PartInfo, PullConfig } from "../index.js";
import { Config, PartInfo } from "../index.js";
export declare function defaultIsFile(info: PartInfo): boolean;

@@ -8,5 +8,2 @@ export declare function make({ headers, onFile: onPart, onField, onError, onDone, isFile, maxParts, maxTotalSize, maxPartSize, maxFieldSize, }: Config): {

export declare function decodeField(info: PartInfo, value: Uint8Array): string;
export declare function isFile(part: Part): part is File;
export declare function isField(part: Part): part is Field;
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

18

dist/dts/node.d.ts
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import type { IncomingHttpHeaders } from "node:http";
import * as MP from "./index.js";
import { Duplex, Readable } from "node:stream";
export type Part = MP.Field | FileStream;
export type Part = Field | FileStream;
export interface Field {
readonly _tag: "Field";
readonly info: MP.PartInfo;
readonly value: Uint8Array;
}
export interface MultipastaStream extends Duplex {
on(event: "field", listener: (field: MP.Field) => void): this;
on(event: "field", listener: (field: Field) => void): this;
on(event: "file", listener: (file: FileStream) => void): this;

@@ -23,5 +30,8 @@ on(event: "close", listener: () => void): this;

}
export type NodeConfig = Omit<MP.BaseConfig, "headers"> & {
readonly headers: IncomingHttpHeaders;
};
export declare class MultipastaStream extends Duplex {
#private;
constructor(config: MP.BaseConfig);
constructor(config: NodeConfig);
_read(_size: number): void;

@@ -31,3 +41,3 @@ _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null | undefined) => void): void;

}
export declare const make: (config: MP.BaseConfig) => MultipastaStream;
export declare const make: (config: NodeConfig) => MultipastaStream;
export declare class FileStream extends Readable {

@@ -34,0 +44,0 @@ readonly info: MP.PartInfo;

@@ -5,5 +5,2 @@ import * as internal from "./internal/multipart.js";

export const decodeField = internal.decodeField;
export const isFile = internal.isFile;
export const isField = internal.isField;
export const makePull = internal.makePull;
//# sourceMappingURL=index.js.map

@@ -220,114 +220,2 @@ import * as CT from "./contentType.js";

}
export function isFile(part) {
return part._tag === "File";
}
export function isField(part) {
return part._tag === "Field";
}
class FileImpl {
info;
pull;
_tag = "File";
filename;
constructor(info, pull) {
this.info = info;
this.pull = pull;
this.filename = info.filename;
}
buffer = [];
hasData = false;
finished = false;
read(cb) {
if (this.hasData) {
const buf = this.buffer;
this.buffer = [];
this.hasData = false;
cb(buf);
if (this.finished) {
cb(null);
}
} else if (this.finished) {
cb(null);
} else {
this.pull(() => this.read(cb));
}
}
}
function noop() {}
export function makePull(config) {
let partBuffer = [];
let error = null;
let hasData = false;
let ended = false;
function addError(err) {
if (error === null) {
error = {
_tag: "MultipartPullError",
errors: [err]
};
hasData = true;
} else {
;
error.errors.push(err);
}
}
const parser = make({
...config,
onField(info, value) {
partBuffer.push({
_tag: "Field",
info,
value
});
hasData = true;
},
onFile(info) {
const file = new FileImpl(info, pull);
partBuffer.push(file);
hasData = true;
return function (chunk) {
if (chunk === null) {
file.finished = true;
} else {
file.buffer.push(chunk);
file.hasData = true;
}
};
},
onError: addError,
onDone() {}
});
function pull(cb) {
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) {
for (let i = 0; i < chunk.length; i++) {
parser.write(chunk[i]);
}
}
cb();
});
}
return function loop(cb) {
if (hasData) {
const result = partBuffer;
partBuffer = [];
hasData = false;
cb(error, result);
pull(noop);
} else if (ended) {
cb(error, null);
} else {
pull(function () {
loop(cb);
});
}
};
}
//# sourceMappingURL=multipart.js.map
{
"name": "multipasta",
"version": "0.1.7",
"version": "0.1.8",
"description": "",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -63,38 +63,1 @@ import * as internal from "./internal/multipart.js"

internal.decodeField
// pull model
export interface File {
readonly _tag: "File"
readonly filename: string
readonly info: PartInfo
readonly read: (cb: (chunk: ReadonlyArray<Uint8Array> | null) => void) => void
}
export interface Field {
readonly _tag: "Field"
readonly info: PartInfo
readonly value: Uint8Array
}
export const isFile: (part: Part) => part is File = internal.isFile
export const isField: (part: Part) => part is Field = internal.isField
export type Part = File | Field
export type PullConfig<E> = BaseConfig & {
readonly pull: (
cb: (err: E | null, chunk: ReadonlyArray<Uint8Array> | null) => void,
) => void
}
export interface MultipartPullError<E> {
readonly _tag: "MultipartPullError"
readonly errors: ReadonlyArray<MultipartError | E>
}
export const makePull: <E = never>(
config: PullConfig<E>,
) => (
cb: (err: MultipartPullError<E> | null, part: readonly Part[] | null) => void,
) => void = internal.makePull

@@ -1,11 +0,2 @@

import {
Config,
Field,
File,
MultipartError,
MultipartPullError,
Part,
PartInfo,
PullConfig,
} from "../index.js"
import { Config, MultipartError, PartInfo } from "../index.js"
import * as CT from "./contentType.js"

@@ -264,121 +255,1 @@ import * as HP from "./headers.js"

}
export function isFile(part: Part): part is File {
return part._tag === "File"
}
export function isField(part: Part): part is Field {
return part._tag === "Field"
}
class FileImpl implements File {
readonly _tag = "File"
readonly filename: string
constructor(
readonly info: PartInfo,
private pull: (cb: () => void) => void,
) {
this.filename = info.filename!
}
buffer: Array<Uint8Array> = []
hasData = false
finished = false
read(cb: (chunk: ReadonlyArray<Uint8Array> | null) => void) {
if (this.hasData) {
const buf = this.buffer
this.buffer = []
this.hasData = false
cb(buf)
if (this.finished) {
cb(null)
}
} else if (this.finished) {
cb(null)
} else {
this.pull(() => this.read(cb))
}
}
}
function noop() {}
export function makePull<E = never>(config: PullConfig<E>) {
let partBuffer: Array<Part> = []
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({
...config,
onField(info, value) {
partBuffer.push({ _tag: "Field", info, value })
hasData = true
},
onFile(info) {
const file = new FileImpl(info, pull)
partBuffer.push(file)
hasData = true
return function (chunk) {
if (chunk === null) {
file.finished = true
} else {
file.buffer.push(chunk)
file.hasData = true
}
}
},
onError: addError,
onDone() {},
})
function pull(cb: () => void) {
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) {
for (let i = 0; i < chunk.length; i++) {
parser.write(chunk[i])
}
}
cb()
})
}
return function loop(
cb: (
err: MultipartPullError<E> | null,
part: ReadonlyArray<Part> | null,
) => void,
) {
if (hasData) {
const result = partBuffer
partBuffer = []
hasData = false
cb(error, result)
pull(noop)
} else if (ended) {
cb(error, null)
} else {
pull(function () {
loop(cb)
})
}
}
}

@@ -0,8 +1,15 @@

import type { IncomingHttpHeaders } from "node:http"
import * as MP from "./index.js"
import { Duplex, Readable } from "node:stream"
export type Part = MP.Field | FileStream
export type Part = Field | FileStream
export interface Field {
readonly _tag: "Field"
readonly info: MP.PartInfo
readonly value: Uint8Array
}
export interface MultipastaStream extends Duplex {
on(event: "field", listener: (field: MP.Field) => void): this
on(event: "field", listener: (field: Field) => void): this
on(event: "file", listener: (file: FileStream) => void): this

@@ -25,2 +32,6 @@ on(event: "close", listener: () => void): this

export type NodeConfig = Omit<MP.BaseConfig, "headers"> & {
readonly headers: IncomingHttpHeaders
}
export class MultipastaStream extends Duplex {

@@ -32,8 +43,8 @@ #parser: MP.Parser

constructor(config: MP.BaseConfig) {
constructor(config: NodeConfig) {
super({ readableObjectMode: true })
this.#parser = MP.make({
...config,
...(config as any),
onField: (info, value) => {
const field: MP.Field = { _tag: "Field", info, value }
const field: Field = { _tag: "Field", info, value }
this.push(field)

@@ -103,3 +114,3 @@ this.emit("field", field)

export const make = (config: MP.BaseConfig): MultipastaStream =>
export const make = (config: NodeConfig): MultipastaStream =>
new MultipastaStream(config)

@@ -106,0 +117,0 @@

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc