Comparing version 0.1.4 to 0.1.6
38
index.js
@@ -13,4 +13,5 @@ var os = require('os'); | ||
options.includeEmptyFields = options.includeEmptyFields || false; | ||
options.inMemory = options.inMemory || false; | ||
// specify the destination directory, else, the uploads will be moved to the temporary dir of the system | ||
// if the destination directory does not exist then assign uploads to the operating system's temporary directory | ||
var dest; | ||
@@ -24,3 +25,2 @@ | ||
// make sure the dest dir exists | ||
mkdirp(dest, function(err) { if (err) throw err; }); | ||
@@ -62,3 +62,3 @@ | ||
if (req.body.hasOwnProperty(fieldname) && val) { | ||
if (req.body.hasOwnProperty(fieldname)) { | ||
if (Array.isArray(req.body[fieldname])) { | ||
@@ -101,3 +101,4 @@ req.body[fieldname].push(val); | ||
size: 0, | ||
truncated: null | ||
truncated: null, | ||
buffer: null | ||
}; | ||
@@ -115,7 +116,13 @@ | ||
var ws = fs.createWriteStream(newFilePath); | ||
fileStream.pipe(ws); | ||
var bufs = []; | ||
var ws; | ||
if (!options.inMemory) { | ||
ws = fs.createWriteStream(newFilePath); | ||
fileStream.pipe(ws); | ||
} | ||
fileStream.on('data', function(data) { | ||
if (data) { file.size += data.length; } | ||
if (options.inMemory) bufs.push(data); | ||
// trigger "file data" event | ||
@@ -125,5 +132,6 @@ if (options.onFileUploadData) { options.onFileUploadData(file, data); } | ||
ws.on('finish', function() { | ||
function onFileStreamEnd() { | ||
file.truncated = fileStream.truncated; | ||
if (!req.files[fieldname]) { req.files[fieldname] = []; } | ||
if (options.inMemory) file.buffer = Buffer.concat(bufs); | ||
req.files[fieldname].push(file); | ||
@@ -136,4 +144,9 @@ // trigger "file end" event | ||
onFinish(); | ||
}); | ||
} | ||
if (options.inMemory) | ||
fileStream.on('end', onFileStreamEnd); | ||
else | ||
ws.on('finish', onFileStreamEnd); | ||
fileStream.on('error', function(error) { | ||
@@ -149,8 +162,13 @@ // trigger "file error" event | ||
ws.on('error', function(error) { | ||
function onFileStreamError(error) { | ||
// trigger "file error" event | ||
if (options.onError) { options.onError(error, next); } | ||
else next(error); | ||
}); | ||
} | ||
if (options.inMemory) | ||
fileStream.on('error', onFileStreamError ); | ||
else | ||
ws.on('error', onFileStreamError ); | ||
}); | ||
@@ -157,0 +175,0 @@ |
{ | ||
"name": "multer", | ||
"version": "0.1.4", | ||
"description": "Connect middleware for handling multipart/form-data", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/expressjs/multer.git", | ||
"homepage": "https://github.com/expressjs/multer" | ||
}, | ||
"bugs": { | ||
"mail": "captain@hacksparrow.com", | ||
"url": "https://github.com/expressjs/multer/issues" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"description": "Middleware for handling `multipart/form-data`.", | ||
"version": "0.1.6", | ||
"contributors": [ | ||
"Hage Yaapa <captain@hacksparrow.com> (http://www.hacksparrow.com)" | ||
], | ||
"license": "MIT", | ||
"repository": "expressjs/multer", | ||
"keywords": [ | ||
@@ -23,3 +15,3 @@ "form", | ||
"form-data", | ||
"connect", | ||
"formdata", | ||
"express", | ||
@@ -29,5 +21,5 @@ "middleware" | ||
"dependencies": { | ||
"busboy": "^0.2.7", | ||
"busboy": "~0.2.9", | ||
"mkdirp": "~0.3.5", | ||
"qs": "^1.2.1" | ||
"qs": "~1.2.2" | ||
}, | ||
@@ -37,14 +29,18 @@ "devDependencies": { | ||
"co": "^3.0.6", | ||
"express": "*", | ||
"mocha": "*", | ||
"express": "^4.9.5", | ||
"mocha": "^1.21.4", | ||
"qs": "^2.2.4", | ||
"rimraf": "^2.2.8", | ||
"supertest": "^0.13.0" | ||
}, | ||
"author": { | ||
"name": "Hage Yaapa", | ||
"email": "captain@hacksparrow.com", | ||
"url": "http://www.hacksparrow.com", | ||
"twitter": "https://twitter.com/hacksparrow" | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
}, | ||
"license": "MIT" | ||
"files": [ | ||
"LICENSE", | ||
"index.js" | ||
], | ||
"scripts": { | ||
"test": "mocha --reporter spec --bail --check-leaks" | ||
} | ||
} |
@@ -45,6 +45,7 @@ # Multer [![Build Status](https://travis-ci.org/expressjs/multer.svg?branch=master)](https://travis-ci.org/expressjs/multer) [![NPM version](https://badge.fury.io/js/multer.svg)](https://badge.fury.io/js/multer) | ||
9. `truncated` - If the file was truncated due to size limitation | ||
10. `buffer` - Raw data (is null unless the inMemory option is true) | ||
## Options | ||
Multer accepts an options object, the most basic of which is the `dest` property, which tells Multer where to upload the files. In case you omit the options object, the file will be renamed and uploaded to the temporary directory of the system. | ||
Multer accepts an options object, the most basic of which is the `dest` property, which tells Multer where to upload the files. In case you omit the options object, the file will be renamed and uploaded to the temporary directory of the system. If the `inMemory` option is true, no data is written to disk but data is kept in a buffer accessible in the file object. | ||
@@ -58,2 +59,3 @@ By the default, Multer will rename the files so as to avoid name conflicts. The renaming function can be customized according to your needs. | ||
* `includeEmptyFields` | ||
* `inMemory` | ||
* `rename(fieldname, filename)` | ||
@@ -122,2 +124,10 @@ * `onFileUploadStart(file)` | ||
### inMemory | ||
If this Boolean value is true, the file.buffer property holds the data in-memory that Multer would have written to disk. The dest option is still populated and the path property contains the proposed path to save the file. Defaults to `false`. | ||
```js | ||
inMemory: true | ||
``` | ||
### rename(fieldname, filename) | ||
@@ -251,20 +261,2 @@ | ||
## License (MIT) | ||
Copyright (c) 2014 Hage Yaapa <[http://www.hacksparrow.com](http://www.hacksparrow.com)> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
## [MIT Licensed](LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16539
165
7
4
1
259
2
Updatedbusboy@~0.2.9
Updatedqs@~1.2.2