WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 7b6dcd3

Browse files
authored
fix: Avoid transcoding streaming output with default options (#360)
1 parent cdb38b7 commit 7b6dcd3

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

lib/dest/write-contents/write-stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function writeStream(file, optResolver, onWritten) {
3131
// TODO: should this use a clone?
3232
var streams = [file.contents];
3333

34-
if (encoding && encoding.enc !== DEFAULT_ENCODING) {
34+
if (encoding && codec.enc !== DEFAULT_ENCODING) {
3535
streams.push(getCodec(DEFAULT_ENCODING).decodeStream());
3636
streams.push(codec.encodeStream());
3737
}

test/dest.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,31 @@ describeStreams('.dest()', function (stream) {
697697
);
698698
});
699699

700+
it('does not do any transcoding with encoding defaulted (buffer)', function (done) {
701+
var expectedContents = fs.readFileSync(ranBomInputPath);
702+
var file = new File({
703+
base: inputBase,
704+
path: inputPath,
705+
contents: expectedContents,
706+
});
707+
708+
function assert(files) {
709+
var outputContents = fs.readFileSync(outputPath);
710+
711+
expect(files.length).toEqual(1);
712+
expect(outputContents).toEqual(expectedContents);
713+
}
714+
715+
pipeline(
716+
[
717+
from([file]),
718+
vfs.dest(outputBase),
719+
concatArray(assert),
720+
],
721+
done
722+
);
723+
});
724+
700725
it('does not do any transcoding with encoding option set to false (buffer)', function (done) {
701726
var expectedContents = fs.readFileSync(ranBomInputPath);
702727
var file = new File({
@@ -722,6 +747,31 @@ describeStreams('.dest()', function (stream) {
722747
);
723748
});
724749

750+
it('does not do any transcoding with encoding defaulted (stream)', function (done) {
751+
var expectedContents = fs.readFileSync(ranBomInputPath);
752+
var file = new File({
753+
base: inputBase,
754+
path: inputPath,
755+
contents: fs.createReadStream(ranBomInputPath),
756+
});
757+
758+
function assert(files) {
759+
var outputContents = fs.readFileSync(outputPath);
760+
761+
expect(files.length).toEqual(1);
762+
expect(outputContents).toEqual(expectedContents);
763+
}
764+
765+
pipeline(
766+
[
767+
from([file]),
768+
vfs.dest(outputBase),
769+
concatArray(assert),
770+
],
771+
done
772+
);
773+
});
774+
725775
it('does not do any transcoding with encoding option set to false (stream)', function (done) {
726776
var expectedContents = fs.readFileSync(ranBomInputPath);
727777
var file = new File({

0 commit comments

Comments
 (0)