Skip to content

Commit

Permalink
Use promisify
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Martins Nápoli <napoli.tiago96@gmail.com>
  • Loading branch information
tiagonapoli committed Aug 9, 2020
1 parent 26be719 commit 18ada3d
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';
const {constants: BufferConstants} = require('buffer');
const {pipeline} = require('stream');
const {promisify} = require('util');
const bufferStream = require('./buffer-stream');

const streamPipelinePromisified = promisify(pipeline);

class MaxBufferError extends Error {
constructor() {
super('maxBuffer exceeded');
Expand Down Expand Up @@ -33,14 +36,7 @@ async function getStream(inputStream, options) {
reject(error);
};

pipeline(inputStream, stream, error => {
if (error) {
rejectPromise(error);
return;
}

resolve();
});
streamPipelinePromisified(inputStream, stream).then(resolve, rejectPromise);

stream.on('data', () => {
if (stream.getBufferedLength() > maxBuffer) {
Expand Down

0 comments on commit 18ada3d

Please sign in to comment.