skipperjs / skipper-postgresql

Skipper Adapter for PostgreSQL and Sails.js
6 stars 2 forks source link

TypeError: "list" argument must be an Array of Buffer or Uint8Array instances #6

Open zazeblik opened 6 years ago

zazeblik commented 6 years ago

config/http.js

module.exports.http = {
  middleware: {order: [
      'startRequestTimer',
      'cookieParser',
      'session',
      'myRequestLogger',
      'bodyParser',
      'handleBodyParserError',
      'compress',
      'methodOverride',
      'poweredBy',
      '$custom',
      'router',
      'www',
      'favicon',
      '404',
      '500'
    ],
    bodyParser: require('skipper')({strict: true, extended: true})

  },
  // cache: 31557600000
};

config/skipper.js

module.exports.skipper = {
  adapter: require('skipper-postgresql'),
  maxBytes: 1000000000,
  connection: 'postgres://xxx:xxx@localhost:5432/calls',
  fileTable: 'files'
}

api/controllers/FileController.js

module.exports = {
  upload: function (req, res) {
    req.file('upload').upload(sails.config.skipper, function (err, files) {
      if (err) return res.negotiate(err);
      res.ok(files)
    })
  },
  download: function (req, res) {
    var SkipperAdapter = sails.config.skipper.adapter;
    SkipperAdapter(sails.config.skipper).read(req.param('fd'), function (err, file) {
      if (err) return res.negotiate(err);
      res.send(new Buffer(file))
    })
  }
}

If you upload a file with a size of 200kb, an error occurs

buffer.js:422
    throw new TypeError(kConcatErrMsg);
    ^

TypeError: "list" argument must be an Array of Buffer or Uint8Array instances
    at Function.Buffer.concat (buffer.js:422:11)
    at PostgresWritableStream._write (/home/nrp/Документы/nodejs/calls_records/node_modules/skipper-postgresql/dist/PostgresWritableStream.js:60:22)
    at doWrite (_stream_writable.js:387:12)
    at writeOrBuffer (_stream_writable.js:373:5)
    at PostgresWritableStream.Writable.write (_stream_writable.js:290:11)
    at Transform.ondata (_stream_readable.js:642:20)
    at emitOne (events.js:115:13)
    at Transform.emit (events.js:210:7)
    at addChunk (_stream_readable.js:266:12)
    at readableAddChunk (_stream_readable.js:253:11)
    at Transform.Readable.push (_stream_readable.js:211:10)
    at Transform.push (_stream_transform.js:147:32)
    at /home/nrp/Документы/nodejs/calls_records/node_modules/skipper/standalone/Upstream/build-renamer-stream.js:58:19
    at determineBasename (/home/nrp/Документы/nodejs/calls_records/node_modules/skipper/standalone/Upstream/build-renamer-stream.js:47:16)
    at Transform.__renamer__._transform (/home/nrp/Документы/nodejs/calls_records/node_modules/skipper/standalone/Upstream/build-renamer-stream.js:49:7)
    at Transform._read (_stream_transform.js:186:10)
    at Transform._write (_stream_transform.js:174:12)
    at doWrite (_stream_writable.js:387:12)
    at writeOrBuffer (_stream_writable.js:373:5)
    at Transform.Writable.write (_stream_writable.js:290:11)
    at Upstream.ondata (_stream_readable.js:642:20)
    at emitOne (events.js:115:13)
    at Upstream.emit (events.js:210:7)
    at Upstream.Readable.read (_stream_readable.js:478:10)
    at flow (_stream_readable.js:849:34)
    at resume_ (_stream_readable.js:831:3)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Enteee commented 5 years ago

The issue seems be related to this adapter concatenating an internal node structure which is no longer a list of buffers in newer node versions.

I solved this issue in my fork by buffering all those buffers myself.