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

formstream

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formstream - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

10

History.md
0.0.6 / 2013-07-15
==================
* added test cases for chaining call (@xingrz)
* improved docs (@xingrz)
* added chaining support (@xingrz)
* api doc
* fixed test causes
* update dependencies version
0.0.5 / 2012-11-06

@@ -3,0 +13,0 @@ ==================

2

index.js

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

module.exports = process.env.FORMSTREAM_COV ? require('./lib-cov/formstream') : require('./lib/formstream');
module.exports = require('./lib/formstream');
/*!
* formstream - lib/formstream.js
* Copyright(c) 2012 fengmk2 <fengmk2@gmail.com>
* Copyright(c) 2012 - 2013 fengmk2 <fengmk2@gmail.com>
* MIT Licensed

@@ -25,3 +25,3 @@ *

*
*
*/

@@ -76,3 +76,3 @@

* Set total stream size.
*
*
* You know total stream data size and you want to set `Content-Length` in headers.

@@ -102,6 +102,8 @@ */

}
// end padding data size
size += this._endData.length;
this._contentLength = size;
return this;
};

@@ -130,2 +132,4 @@

this.stream(name, fs.createReadStream(filepath), filename, mimeType);
return this;
};

@@ -136,2 +140,4 @@

process.nextTick(this.resume.bind(this));
return this;
};

@@ -149,2 +155,4 @@

process.nextTick(this.resume.bind(this));
return this;
};

@@ -159,2 +167,4 @@

process.nextTick(this.resume.bind(this));
return this;
};

@@ -164,3 +174,3 @@

// ending format:
//
//
// --{boundary}--\r\n

@@ -245,3 +255,3 @@ this.emit('data', this._endData);

}
return this;
return this;
};

@@ -248,0 +258,0 @@

This software is licensed under the MIT License.
Copyright (C) 2012 by fengmk2 <fengmk2@gmail.com>
Copyright (C) 2012 - 2013 by fengmk2 <fengmk2@gmail.com>

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "formstream",
"version": "0.0.5",
"version": "0.0.6",
"description": "A multipart/form-data encoded stream, helper for file upload.",
"main": "index.js",
"directories": {
"example": "example",
"test": "test"
},
"scripts": {
"test": "make test"
"test": "make test-all",
"blanket": { "pattern": "formstream/lib" },
"travis-cov": { "threshold": 100 }
},

@@ -27,5 +25,5 @@ "repository": {

"dependencies": {
"mime": "1.2.7",
"mime": "1.2.9",
"buffer-concat": "0.0.1",
"pause-stream": "0.0.6"
"pause-stream": ">=0.0.10"
},

@@ -36,3 +34,6 @@ "devDependencies": {

"pedding": "*",
"jscover": "*",
"blanket": "*",
"travis-cov": "*",
"coveralls": "*",
"mocha-lcov-reporter": "*",
"mocha": "*"

@@ -39,0 +40,0 @@ },

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

formstream [![Build Status](https://secure.travis-ci.org/fengmk2/formstream.png)](http://travis-ci.org/fengmk2/formstream)
formstream [![Build Status](https://secure.travis-ci.org/fengmk2/formstream.png)](http://travis-ci.org/fengmk2/formstream) [![Coverage Status](https://coveralls.io/repos/fengmk2/formstream/badge.png)](https://coveralls.io/r/fengmk2/formstream)
==========

@@ -8,4 +8,2 @@

jscoverage: [100%](http://fengmk2.github.com/coverage/formstream.html)
## Install

@@ -17,3 +15,3 @@

## Usage
## Quick Start

@@ -30,4 +28,3 @@ ```js

// other form fields
form.field('foo', 'fengmk2');
form.field('love', 'aerdeng');
form.field('foo', 'fengmk2').field('love', 'aerdeng');

@@ -54,3 +51,3 @@ // even send file content buffer directly

### `form.setTotalStreamSize(size)`: Upload file with `Content-Length`
### Uploading with known `Content-Length`

@@ -85,7 +82,151 @@ If you know the `ReadStream` total size and you must to set `Content-Length`.

## License
### Chaining
```js
var stat = require('fs').statSync;
var form = require('formstream')();
form.field('status', 'share picture')
.field('access_token', 'dk10f88bhza-39kgna.d91')
.file('pic', './logo.png', 'logo.png')
.setTotalStreamSize(stat('./logo.png').size)
.pipe(/* your request stream */);
```
## API Doc
### formstream()
Create a form instance.
#### Returns
`form`
### FormStream#field(name, value)
Add a normal field to the form.
#### Arguments
- **name** String - Name of field
- **value** String - Value of field
#### Returns
`form`
### FormStream#file(name, filepath[, filename])
Add a local file to be uploaded to the form.
#### Arguments
- **name** String - Name of file field
- **filepath** String - Local path of the file to be uploaded
- ***filename*** String - Optional. Name of the file (will be the base name of `filepath` if empty)
#### Returns
`form`
### FormStream#buffer(name, buffer, filename[, contentType])
Add a buffer as a file to upload.
#### Arguments
- **name** String - Name of field
- **buffer** Buffer - The buffer to be uploaded
- **filename** String - The file name that tells the remote server
- ***contentType*** String - Optional. Content-Type (aka. MIME Type) of content (will be infered with `filename` if empty)
#### Returns
`form`
### FormStream#stream(name, stream, filename[, contentType])
Add a readable stream as a file to upload. Event 'error' will be emitted if an error occured.
#### Arguments
- **name** String - Name of field
- **stream** [stream.Readable](http://nodejs.org/api/stream.html#stream_class_stream_readable) - A readable stream to be piped
- **filename** String - The file name that tells the remote server
- ***contentType*** String - Optional. Content-Type (aka. MIME Type) of content (will be infered with `filename` if empty)
#### Returns
`form`
### FormStream#setTotalStreamSize(size)
In some case you may want a `Content-Length` sent with the POST request. If the total size of streams are known, you can tell it with this method.
#### Arguments
- **size** Number - Size of total stream in bytes.
#### Returns
`form`
### FormStream#headers(headers)
Add headers to the form payload.
#### Arguments
- **headers** Object - An object contains headers you want to add
#### Example
```js
form.headers({
'Authorization': 'Bearer kei2akc92jmznvnkeh09sknzdk',
'Accept': 'application/vnd.github.v3.full+json'
})
```
#### Returns
Object - Headers to be sent.
### Event 'error'
Emitted if there was an error receiving data.
### Event 'data'
The 'data' event emits when a Buffer was used.
See [Node.js Documentation](http://nodejs.org/api/stream.html#stream_event_data) for more.
### Event 'end'
Emitted when the stream has received no more 'data' events will happen.
See [Node.js Documentation](http://nodejs.org/api/stream.html#stream_event_end) for more.
## Authors
```bash
$ git summary
project : formstream
repo age : 9 months
active : 12 days
commits : 24
files : 14
authors :
19 fengmk2 79.2%
5 XiNGRZ 20.8%
```
## License
(The MIT License)
Copyright (c) 2012 fengmk2 &lt;fengmk2@gmail.com&gt;
Copyright (c) 2012 - 2013 fengmk2 &lt;fengmk2@gmail.com&gt;

@@ -109,2 +250,2 @@ Permission is hereby granted, free of charge, to any person obtaining

TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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