UNPKG

@ethersphere/bee-js

Version:
26 lines (25 loc) 838 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeTar = void 0; const fs_1 = require("fs"); async function writeTar(collection, tarStream) { for (const item of collection) { tarStream.beginFile(item.path, item.size); if (item.fsPath) { const stream = (0, fs_1.createReadStream)(item.fsPath); for await (const chunk of stream) { await tarStream.appendFile(chunk); } await tarStream.endFile(); stream.close(); } else if (item.file) { await tarStream.appendFile(new Uint8Array(await item.file.arrayBuffer())); await tarStream.endFile(); } else { throw new Error('Invalid collection item'); } } } exports.writeTar = writeTar;