You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.2 KiB
27 lines
1.2 KiB
"use strict"; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = void 0; |
|
const fs = require("fs"); |
|
const zlib = require("zlib"); |
|
const stream = require("stream"); |
|
const iterable_to_stream_1 = require("iterable-to-stream"); |
|
function writeToFile(filename, data) { |
|
return writeToFileIterable(filename, [data]); |
|
} |
|
exports.writeToFile = writeToFile; |
|
function writeToFileIterable(filename, data) { |
|
const sourceStream = stream.Readable.from ? stream.Readable.from(data) : iterable_to_stream_1.iterableToStream(data); |
|
const writeStream = fs.createWriteStream(filename); |
|
const zip = filename.match(/\.gz$/) ? zlib.createGzip() : new stream.PassThrough(); |
|
return sourceStream.pipe(zip).pipe(writeStream); |
|
} |
|
exports.writeToFileIterable = writeToFileIterable; |
|
function writeToFileIterableP(filename, data) { |
|
const stream = writeToFileIterable(filename, data); |
|
return new Promise((resolve, reject) => { |
|
stream.on('finish', () => resolve()); |
|
stream.on('error', (e) => reject(e)); |
|
}); |
|
} |
|
exports.writeToFileIterableP = writeToFileIterableP; |
|
//# sourceMappingURL=fileWriter.js.map
|