Skip to content

Commit

Permalink
feat: Replace lazystream with streamx Composer (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored Jun 11, 2023
1 parent ebe6498 commit a80dae3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
35 changes: 19 additions & 16 deletions lib/src/read-contents/read-stream.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

var fs = require('graceful-fs');
var composer = require('stream-composer');
var lazystream = require('lazystream');
var Composer = require('stream-composer');

var getCodec = require('../../codecs');
var DEFAULT_ENCODING = require('../../constants').DEFAULT_ENCODING;
Expand All @@ -16,25 +15,29 @@ function streamFile(file, optResolver, onRead) {

var filePath = file.path;

file.contents = new lazystream.Readable(function () {
var contents = fs.createReadStream(filePath);
file.contents = new Composer({
open: function (cb) {
var contents = fs.createReadStream(filePath);
var streams = [contents];

var streams = [contents];
if (encoding) {
var removeBOM =
codec.bomAware && optResolver.resolve('removeBOM', file);

if (encoding) {
var removeBOM = codec.bomAware && optResolver.resolve('removeBOM', file);
if (removeBOM || codec.enc !== DEFAULT_ENCODING) {
streams.push(codec.decodeStream({ removeBOM: removeBOM }));
streams.push(getCodec(DEFAULT_ENCODING).encodeStream());
}
}

if (removeBOM || codec.enc !== DEFAULT_ENCODING) {
streams.push(codec.decodeStream({ removeBOM: removeBOM }));
streams.push(getCodec(DEFAULT_ENCODING).encodeStream());
if (streams.length > 1) {
this.setPipeline(streams);
} else {
this.setReadable(contents);
}
}

if (streams.length > 1) {
return composer.pipeline(streams);
} else {
return contents;
}
cb();
},
});

onRead();
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"graceful-fs": "^4.2.11",
"iconv-lite": "^0.6.3",
"is-valid-glob": "^1.0.0",
"lazystream": "^1.0.1",
"lead": "^4.0.0",
"normalize-path": "3.0.0",
"resolve-options": "^2.0.0",
Expand Down

0 comments on commit a80dae3

Please sign in to comment.