Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4
@@ -6,2 +6,19 @@ # Change log | ||
## 2.0.0-alpha.4 - 2017-02-14 | ||
- Feature: add file type detection | ||
## 2.0.0-alpha.3 - 2016-12-22 | ||
- Feature: unlink file as soon as it's opened | ||
## 2.0.0-alpha.2 - 2016-10-02 | ||
- Feature: use LIMIT_FILE_COUNT when receiving too many files | ||
## 2.0.0-alpha.1 - 2016-10-01 | ||
- Feature: switch to stream based API | ||
- Feature: throw error when passing old options | ||
## 1.2.0 - 2016-08-04 | ||
@@ -8,0 +25,0 @@ |
@@ -25,14 +25,9 @@ var is = require('type-is') | ||
result.files.forEach(function (file) { | ||
var stream = fs.createReadStream(file.path) | ||
file.stream = fs.createReadStream(file.path) | ||
stream.on('open', function () { | ||
file.stream.on('open', function () { | ||
fs.unlink(file.path, function () {}) | ||
}) | ||
appendFile({ | ||
fieldName: file.fieldName, | ||
originalName: file.originalName, | ||
size: file.size, | ||
stream: stream | ||
}) | ||
appendFile(file) | ||
}) | ||
@@ -39,0 +34,0 @@ |
@@ -0,4 +1,6 @@ | ||
var path = require('path') | ||
var pify = require('pify') | ||
var temp = require('fs-temp') | ||
var Busboy = require('busboy') | ||
var FileType = require('stream-file-type') | ||
@@ -54,3 +56,5 @@ var pump = pify(require('pump')) | ||
fieldName: fieldname, | ||
originalName: filename | ||
originalName: filename, | ||
clientReportedMimeType: mimetype, | ||
clientReportedFileExtension: path.extname(filename) | ||
} | ||
@@ -72,2 +76,3 @@ | ||
var target = temp.createWriteStream() | ||
var detector = new FileType() | ||
@@ -78,3 +83,3 @@ var fileClosed = new Promise(function (resolve) { | ||
var promise = pump(fileStream, target) | ||
var promise = pump(fileStream, detector, target) | ||
.then(function () { | ||
@@ -84,4 +89,9 @@ return fileClosed | ||
.then(function () { | ||
return detector.fileTypePromise() | ||
}) | ||
.then(function (fileType) { | ||
file.path = target.path | ||
file.size = target.bytesWritten | ||
file.detectedMimeType = (fileType ? fileType.mime : null) | ||
file.detectedFileExtension = (fileType ? '.' + fileType.ext : '') | ||
return file | ||
@@ -88,0 +98,0 @@ }) |
{ | ||
"name": "multer", | ||
"description": "Middleware for handling `multipart/form-data`.", | ||
"version": "2.0.0-alpha.3", | ||
"version": "2.0.0-alpha.4", | ||
"contributors": [ | ||
@@ -28,2 +28,3 @@ "Hage Yaapa <captain@hacksparrow.com> (http://www.hacksparrow.com)", | ||
"pump": "^1.0.1", | ||
"stream-file-type": "^0.1.1", | ||
"type-is": "^1.6.13" | ||
@@ -42,3 +43,3 @@ }, | ||
"engines": { | ||
"node": ">= 0.12.0" | ||
"node": ">= 4.0.0" | ||
}, | ||
@@ -45,0 +46,0 @@ "files": [ |
@@ -75,3 +75,9 @@ # 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) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | ||
`stream` | Stream of file | ||
`detectedMimeType` | The detected mime-type, or null if we failed to detect | ||
`detectedFileExtension` | The typical file extension for files of the detected type, or empty string if we failed to detect (with leading `.` to match `path.extname`) | ||
`clientReportedMimeType` | The mime type reported by the client using the `Content-Type` header, or null<sup>1</sup> if the header was absent | ||
`clientReportedFileExtension` | The extension of the file uploaded (as reported by `path.extname`) | ||
<sup>1</sup> Currently returns `text/plain` if header is absent, this is a bug and it will be fixed in a patch release. Do not rely on this behavior. | ||
### `multer(opts)` | ||
@@ -78,0 +84,0 @@ |
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
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
18558
259
172
8
+ Addedstream-file-type@^0.1.1
+ Addedfile-type@4.4.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstream-file-type@0.1.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)