Fix corrupt outputs
This commit is contained in:
parent
affa9336a3
commit
05b855a40a
1 changed files with 10 additions and 7 deletions
17
index.js
17
index.js
|
@ -5,7 +5,7 @@ const tarPack = tar.pack();
|
||||||
const ZstdCodec = require('zstd-codec').ZstdCodec;
|
const ZstdCodec = require('zstd-codec').ZstdCodec;
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
const COMPRESSION_LEVEL = 3;
|
const COMPRESSION_LEVEL = 5;
|
||||||
|
|
||||||
// async readdir
|
// async readdir
|
||||||
const readdir = async (path, options) => {
|
const readdir = async (path, options) => {
|
||||||
|
@ -84,7 +84,7 @@ async function packDirectory(directory, options = {}) {
|
||||||
const fileWriteStream = getFileWriteStream(options);
|
const fileWriteStream = getFileWriteStream(options);
|
||||||
|
|
||||||
tarPack.pipe(fileWriteStream);
|
tarPack.pipe(fileWriteStream);
|
||||||
//writeFirstEntry(options, tarPack);
|
writeFirstEntry(options, tarPack);
|
||||||
|
|
||||||
await walkAndRun(async (file) => {
|
await walkAndRun(async (file) => {
|
||||||
try{
|
try{
|
||||||
|
@ -92,7 +92,7 @@ async function packDirectory(directory, options = {}) {
|
||||||
|
|
||||||
// Must be chunked to avoid issues with fixed memory limits.
|
// Must be chunked to avoid issues with fixed memory limits.
|
||||||
const chunkIterator = (() => {
|
const chunkIterator = (() => {
|
||||||
const chunkSize = 128;
|
const chunkSize = 2048;
|
||||||
let position = 0;
|
let position = 0;
|
||||||
|
|
||||||
const iterator = {
|
const iterator = {
|
||||||
|
@ -100,7 +100,7 @@ async function packDirectory(directory, options = {}) {
|
||||||
const endIndex = position + chunkSize;
|
const endIndex = position + chunkSize;
|
||||||
const result = {
|
const result = {
|
||||||
value: contents.slice(position, endIndex),
|
value: contents.slice(position, endIndex),
|
||||||
done: endIndex >= contents.length,
|
done: position >= contents.length,
|
||||||
};
|
};
|
||||||
|
|
||||||
position = endIndex;
|
position = endIndex;
|
||||||
|
@ -170,14 +170,17 @@ async function unpackDirectory(directory, options = {}) {
|
||||||
contents = zstd.decompress(contents);
|
contents = zstd.decompress(contents);
|
||||||
|
|
||||||
if(!/^\./.test(header.name)) {
|
if(!/^\./.test(header.name)) {
|
||||||
console.log(header.name)
|
if(header.name == 'index.html') {
|
||||||
|
console.log(String.fromCharCode.apply(null, contents))
|
||||||
|
}
|
||||||
const writePath = path.join(directory, header.name);
|
const writePath = path.join(directory, header.name);
|
||||||
fs.promises.mkdir(path.dirname(writePath), { recursive: true });
|
fs.promises.mkdir(path.dirname(writePath), { recursive: true });
|
||||||
var fileWriteStream = fs.createWriteStream(writePath);
|
var fileWriteStream = fs.createWriteStream(writePath);
|
||||||
fileWriteStream.end(contents);
|
fileWriteStream.write(contents);
|
||||||
|
fileWriteStream.end();
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
fileWriteStream.resume();
|
fileStream.resume();
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue