memory.js 475 B

123456789101112131415161718192021
  1. var concat = require('concat-stream')
  2. function MemoryStorage (opts) {}
  3. MemoryStorage.prototype._handleFile = function _handleFile (req, file, cb) {
  4. file.stream.pipe(concat({ encoding: 'buffer' }, function (data) {
  5. cb(null, {
  6. buffer: data,
  7. size: data.length
  8. })
  9. }))
  10. }
  11. MemoryStorage.prototype._removeFile = function _removeFile (req, file, cb) {
  12. delete file.buffer
  13. cb(null)
  14. }
  15. module.exports = function (opts) {
  16. return new MemoryStorage(opts)
  17. }