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

formdata-node

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formdata-node - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

lib/util/isReadStream.js

99

lib/FormData.js

@@ -12,2 +12,4 @@ "use strict";

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _map = _interopRequireDefault(require("@babel/runtime/core-js/map"));

@@ -39,2 +41,4 @@

var _promiseFs = _interopRequireDefault(require("promise-fs"));
var _bind = _interopRequireDefault(require("./util/bind"));

@@ -54,6 +58,8 @@

var _isReadable = _interopRequireDefault(require("./util/isReadable"));
var _isStream = _interopRequireDefault(require("./util/isStream"));
var _isFunction = _interopRequireDefault(require("./util/isFunction"));
var _isReadStream = _interopRequireDefault(require("./util/isReadStream"));
var _StreamIterator = _interopRequireDefault(require("./util/StreamIterator"));

@@ -140,3 +146,2 @@

(0, _defineProperty2.default)(this, "delete", name => void this.__content.delete(name));
(0, _defineProperty2.default)(this, "pipe", (dest, options) => this.__stream.pipe(dest, options));
(0, _defineProperty2.default)(this, "forEach", (fn, ctx = null) => {

@@ -154,5 +159,4 @@ for (const [name, value] of this) {

this.__curr = this.__getField();
const read = this.__read;
this.__stream = new _stream.default.Readable({
read
read: this.__read
});

@@ -205,3 +209,3 @@

for (const value of values) {
if ((0, _isReadable.default)(value)) {
if ((0, _isStream.default)(value)) {
// Read the stream content

@@ -256,3 +260,3 @@ yield* (0, _asyncGeneratorDelegate2.default)((0, _asyncIterator2.default)((0, _isFunction.default)(value[_symbol.default.asyncIterator]) ? value : new _StreamIterator.default(value)), _awaitAsyncGenerator2.default);

filename = _path.default.basename(filename);
} else if ((0, _isReadable.default)(value) && (value.path || filename)) {
} else if ((0, _isStream.default)(value) && (value.path || filename)) {
// Readable stream which created from fs.createReadStream

@@ -269,3 +273,3 @@ // have a "path" property. So, we can get a "filename"

if (!((0, _isReadable.default)(value) || (0, _isBuffer.default)(value))) {
if (!((0, _isStream.default)(value) || (0, _isBuffer.default)(value))) {
value = String(value);

@@ -339,2 +343,51 @@ }

/**
* Returns computed length of the FormData content.
* If data contains stream.Readable field(s),
* the method will always return 0.
*
* @return {number}
*/
getComputedLength() {
var _this2 = this;
return (0, _asyncToGenerator2.default)(function* () {
if (_this2.__content.size === 0) {
return 0;
}
let length = 0;
const carriageLength = Buffer.from(_this2.__carriage).length;
for (const [name, {
filename,
values
}] of _this2.__content) {
length += Buffer.from(_this2.__getHeader(name, filename)).length;
for (const value of values) {
if ((0, _isStream.default)(value)) {
if (!(0, _isReadStream.default)(value)) {
return undefined;
}
length += yield _promiseFs.default.stat(value.path).then(({
size
}) => size);
} else if ((0, _isBuffer.default)(value)) {
length += value.length;
} else {
length += Buffer.from(value).length;
}
}
length += carriageLength;
}
length += Buffer.from(_this2.__getFooter()).length;
return length;
})();
}
/**
* Appends a new value onto an existing key inside a FormData object,

@@ -360,6 +413,17 @@ * or adds the key if it does not already exist.

/**
* Returns a string representation of the FormData
*
* @return {string}
*/
toString() {
return "[object FormData]";
}
/**
* Returns a string representation of the FormData
*
* @return {string}
*/
inspect() {

@@ -372,3 +436,7 @@ return "FormData";

}
/**
* @return {IterableIterator<string>}
*/
*keys() {

@@ -379,10 +447,21 @@ for (const key of this.__content.keys()) {

}
/**
* @return {IterableIterator<[string, any]>}
*/
*entries() {
for (const name of this.keys()) {
const values = this.getAll(name);
yield [name, values.length === 1 ? values[0] : values];
const values = this.getAll(name); // Yield each value of a field, like browser-side FormData does.
for (const value of values) {
yield [name, value];
}
}
}
/**
* @return {IterableIterator<any>}
*/
*values() {

@@ -419,3 +498,3 @@ for (const [, values] of this) {

*
* @return {StreamIterator}
* @return {IterableIterator<Promise<Buffer>>}
*

@@ -422,0 +501,0 @@ * @public

2

package.json
{
"name": "formdata-node",
"version": "1.4.1",
"version": "1.5.0",
"description": "FormData implementation for Node.js. Built over Readable stream and async generators. Can be used to communicate between servers with multipart/form-data format.",

@@ -5,0 +5,0 @@ "repository": "octet-stream/form-data",

@@ -79,3 +79,4 @@ # FormData

Returns an internal Readable stream.
Returns an internal Readable stream. Use it to send queries, but don't push
anything into it.

@@ -110,3 +111,3 @@ ##### `get headers() -> {object}`

##### `get(name) -> {string | Buffer | stream.Readable}`
##### `get(name) -> {string | Buffer | stream.Readable | fs.ReadStream}`

@@ -118,3 +119,3 @@ Returns the first value associated with the given name.

##### `getAll(name) -> {Array<string | Buffer | stream.Readable>}`
##### `getAll(name) -> {Array<string | Buffer | stream.Readable | fs.ReadStream>}`

@@ -137,4 +138,9 @@ Returns all the values associated with a given key from within a **FormData** object.

#### `forEach(callback[, ctx]) -> {void}`
##### `getComputedLength() -> {Promise<number>}`
Returns computed length of the FormData content. If FormData instance contains
a field with stream.Readable value, this method will always return `undefined`.
##### `forEach(callback[, ctx]) -> {void}`
Executes a given **callback** for each field of the FormData instance

@@ -148,19 +154,19 @@

##### `keys() -> {iterator}`
##### `keys() -> {IterableIterator<string>}`
Returns an **[iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)** allowing to go through the **FormData** keys
##### `values() -> {iterator}`
##### `values() -> {IterableIterator<any>}`
Returns an **[iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)** allowing to go through the **FormData** values
##### `entries() -> {iterator}`
##### `entries() -> {IterableIterator<[string, any]>}`
Returns an **[iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)** allowing to go through the **FormData** key/value pairs
##### `[Symbol.iterator]() -> {iterator}`
##### `[Symbol.iterator]() -> {IterableIterator<[string, any]>}`
An alias of [FormData#entries](#entries---iterator)
##### `[Symbol.asyncIterator]() -> {asyncIterator}`
##### `[Symbol.asyncIterator]() -> {IterableIterator<Promise<Buffer>>}`

@@ -167,0 +173,0 @@ Returns an async iterator allowing to read a data from internal Readable stream using **for-await** syntax.

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