Answers for "stream to promise"

0

stream to promise

var getGridFsStreams = function (url, fileId) {
  return new Promise(function (resolve, reject) {
    mongoDBPool.getConnection(url).then(function (db) {
      var gfs = Grid(db, mongo);
      var readstream = gfs.createReadStream({
        _id: fileId
      });

      streamToPromise(readstream).then(function (buffer) {
        var base64 = Buffer(buffer).toString('base64');
        return resolve(base64);
      }).catch(function (err) {
        return reject(err);
      });
    }).catch(function (err) {
      return reject(err);
    });
  });
}
Posted by: Guest on September-17-2021
0

stream to promise

var insertGridFsStreams = function (url, metadata, path) {
  return new Promise(function (resolve, reject) {
    mongoDBPool.getConnection(url).then(function (db) {
      var gfs = Grid(db, mongo);
      var writestream = gfs.createWriteStream({
        filename: metadata.filename,
        metadata: metadata
      });
      var writableStream = fs.createReadStream(path).pipe(writestream);
      streamToPromise(writableStream);
      writestream.on('close', function (file) {
        if (file.filename) {
          return resolve(true);
        } else {
          return reject('fail insert gridfs streams');
        }
      });
    }).catch(function (err) {
      return resolve(err);
    });
  });
}
Posted by: Guest on September-17-2021

Browse Popular Code Answers by Language