then-busboy
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -8,4 +8,2 @@ "use strict"; | ||
var _os = require("os"); | ||
var _fs = require("fs"); | ||
@@ -19,4 +17,2 @@ | ||
var _nanoid = _interopRequireDefault(require("nanoid")); | ||
var _isPlainObject = _interopRequireDefault(require("./util/isPlainObject")); | ||
@@ -48,7 +44,13 @@ | ||
const onData = ch => void data.push(ch); | ||
const onReadable = () => { | ||
const ch = this.contents.read(); | ||
if (ch != null) { | ||
data.push(ch); | ||
} | ||
}; | ||
const onEnd = () => resolve(Buffer.concat(data)); | ||
this.contents.on("error", reject).on("data", onData).on("end", onEnd); | ||
this.contents.on("error", reject).on("readable", onReadable).on("end", onEnd); | ||
}) | ||
@@ -87,8 +89,9 @@ }); | ||
this.__stream = contents; | ||
this.__filename = filename; | ||
this.__filename = (0, _path.basename)(filename); | ||
this.__basename = base; | ||
this.__extname = ext; | ||
this.__mime = mime; | ||
this.__enc = enc; | ||
this.__path = (0, _path.join)((0, _os.tmpdir)(), `${(0, _nanoid.default)()}_${this.filename}`); | ||
this.__enc = enc; // this.__path = join(tmpdir(), `${nanoid()}_${this.filename}`) | ||
this.__path = filename; | ||
this.toJSON = this.toJSON.bind(this); | ||
@@ -95,0 +98,0 @@ this.inspect = this.inspect.bind(this); |
@@ -8,4 +8,10 @@ "use strict"; | ||
var _stream = require("stream"); | ||
var _fs = require("fs"); | ||
var _path = require("path"); | ||
var _os = require("os"); | ||
var _nanoid = _interopRequireDefault(require("nanoid")); | ||
var _File = _interopRequireDefault(require("../File")); | ||
@@ -25,13 +31,6 @@ | ||
const path = (0, _getFieldPath.default)(fieldname); | ||
const contents = new _stream.Readable({ | ||
read() { | ||
/* noop */ | ||
} | ||
filename = (0, _path.join)((0, _os.tmpdir)(), `${(0, _nanoid.default)()}__${filename}`); | ||
}); | ||
const onData = ch => void contents.push(ch); | ||
function onEnd() { | ||
contents.push(null); | ||
const contents = (0, _fs.createReadStream)(filename); | ||
const file = new _File.default({ | ||
@@ -44,7 +43,5 @@ filename, | ||
cb(null, [path, file]); | ||
} // Busboy doesn't emit an "end" event while file stream have not been read. | ||
// So, we just read the stream and push it to the other [Readable] one. o_O | ||
} | ||
stream.on("error", cb).on("data", onData).on("end", onEnd); | ||
stream.on("end", onEnd).pipe((0, _fs.createWriteStream)(filename)); | ||
} catch (err) { | ||
@@ -51,0 +48,0 @@ return cb(err); |
@@ -91,3 +91,3 @@ "use strict"; | ||
(0, _mapListeners.default)(listeners, (fn, name) => busboy.removeListener(name, fn)); | ||
return resolve((0, _objectDeepFromEntries.default)(entries)); | ||
resolve((0, _objectDeepFromEntries.default)(entries)); | ||
} catch (err) { | ||
@@ -94,0 +94,0 @@ return reject(err); |
{ | ||
"name": "then-busboy", | ||
"description": "Promise-based wrapper around Busboy. Process multipart/form-data content and returns it as a single object.", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"author": "Nick K. <nick.kruchinin@gmail.com>", | ||
@@ -73,3 +73,3 @@ "license": "MIT", | ||
"husky": "0.14.3", | ||
"lint-staged": "7.0.0", | ||
"lint-staged": "7.0.2", | ||
"nyc": "11.6.0", | ||
@@ -79,5 +79,5 @@ "promise-fs": "1.3.0", | ||
"rimraf": "2.6.2", | ||
"sinon": "4.4.8", | ||
"sinon": "4.5.0", | ||
"supertest": "3.0.0" | ||
} | ||
} |
@@ -90,22 +90,2 @@ "use strict"; | ||
}); | ||
(0, _ava.default)("Should have a correct default path", t => { | ||
const spyo = (0, _sinon.spy)(_nanoid.default); | ||
const spydir = (0, _sinon.spy)(_os.tmpdir); | ||
const MockedFile = (0, _proxyquire.default)("../../lib/File", { | ||
nanoid: spyo, | ||
os: { | ||
tmpdir: spydir | ||
} | ||
}).default; | ||
const contents = (0, _fs.createReadStream)(__filename); | ||
const filename = (0, _path.basename)(__filename); | ||
const file = new MockedFile({ | ||
contents, | ||
filename, | ||
mime: "text/javascript", | ||
enc: "utf-8" | ||
}); | ||
const expected = (0, _path.join)(spydir.lastCall.returnValue, `${spyo.lastCall.returnValue}_${filename}`); | ||
t.is(file.path, expected); | ||
}); | ||
(0, _ava.default)("Should correctly read given file from Stream", async t => { | ||
@@ -112,0 +92,0 @@ t.plan(1); |
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
48789
1073
6