audiobookshelf/server/libs/archiver/compress-commons/util/index.js

30 lines
786 B
JavaScript
Raw Normal View History

2022-07-07 03:12:14 +02:00
/**
* node-compress-commons
*
* Copyright (c) 2014 Chris Talkington, contributors.
* Licensed under the MIT license.
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
*/
var Stream = require('stream').Stream;
2022-07-09 01:11:09 +02:00
var PassThrough = require('../../archiverUtils/readableStream').PassThrough;
2022-07-07 03:12:14 +02:00
var util = module.exports = {};
2022-07-09 01:11:09 +02:00
util.isStream = function (source) {
2022-07-07 03:12:14 +02:00
return source instanceof Stream;
};
2022-07-09 01:11:09 +02:00
util.normalizeInputSource = function (source) {
2022-07-07 03:12:14 +02:00
if (source === null) {
return Buffer.alloc(0);
} else if (typeof source === 'string') {
return Buffer.from(source);
} else if (util.isStream(source) && !source._readableState) {
var normalized = new PassThrough();
source.pipe(normalized);
return normalized;
}
return source;
};