You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
523 B

6 years ago
'use strict';
var fileType = require('file-type');
var PassThrough = require('readable-stream/passthrough');
var uuid = require('uuid');
var Vinyl = require('vinyl');
module.exports.file = function (buf, name) {
var ext = fileType(buf) ? '.' + fileType(buf).ext : null;
return new Vinyl({
contents: buf,
path: (name || uuid.v4()) + (ext || '')
});
};
module.exports.stream = function (buf, name) {
var stream = new PassThrough({objectMode: true});
stream.end(module.exports.file(buf, name));
return stream;
};