Update lbry-format
This commit is contained in:
parent
3bc34d5109
commit
cc944a9d3d
3 changed files with 78 additions and 74 deletions
|
@ -87,7 +87,6 @@ async function packDirectory(directory, options = {}) {
|
||||||
writeFirstEntry(options, tarPack);
|
writeFirstEntry(options, tarPack);
|
||||||
|
|
||||||
await walkAndRun(async (file) => {
|
await walkAndRun(async (file) => {
|
||||||
try{
|
|
||||||
contents = await readFile(path.normalize(file));
|
contents = await readFile(path.normalize(file));
|
||||||
|
|
||||||
// Must be chunked to avoid issues with fixed memory limits.
|
// Must be chunked to avoid issues with fixed memory limits.
|
||||||
|
@ -113,7 +112,7 @@ async function packDirectory(directory, options = {}) {
|
||||||
|
|
||||||
contents = zstd.compressChunks(chunkIterator, contents.length, COMPRESSION_LEVEL);
|
contents = zstd.compressChunks(chunkIterator, contents.length, COMPRESSION_LEVEL);
|
||||||
|
|
||||||
let name = path.relative(packRoot, file);
|
let name = path.relative(packRoot, file).replace('\\', '/');
|
||||||
|
|
||||||
if(/^\.\//.test(name)) {
|
if(/^\.\//.test(name)) {
|
||||||
name = name.slice(2);
|
name = name.slice(2);
|
||||||
|
@ -126,9 +125,8 @@ async function packDirectory(directory, options = {}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
await writeStream(entry, contents);
|
await writeStream(entry, contents);
|
||||||
//console.log(contents)
|
|
||||||
entry.end();
|
entry.end();
|
||||||
}catch (e){console.log(e)}
|
|
||||||
}, directory, packRoot);
|
}, directory, packRoot);
|
||||||
tarPack.finalize();
|
tarPack.finalize();
|
||||||
};
|
};
|
||||||
|
@ -154,6 +152,7 @@ function streamToBuffer(stream) {
|
||||||
|
|
||||||
|
|
||||||
async function unpackDirectory(directory, options = {}) {
|
async function unpackDirectory(directory, options = {}) {
|
||||||
|
return new Promise(async (resolve) => {
|
||||||
if(!fs.existsSync(directory)) {
|
if(!fs.existsSync(directory)) {
|
||||||
fs.mkdirSync(directory);
|
fs.mkdirSync(directory);
|
||||||
}
|
}
|
||||||
|
@ -170,12 +169,14 @@ async function unpackDirectory(directory, options = {}) {
|
||||||
contents = zstd.decompress(contents);
|
contents = zstd.decompress(contents);
|
||||||
|
|
||||||
if(!/^\./.test(header.name)) {
|
if(!/^\./.test(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 });
|
|
||||||
var fileWriteStream = fs.createWriteStream(writePath);
|
try {
|
||||||
|
fs.mkdirSync(path.dirname(writePath), { recursive: true });
|
||||||
|
} catch (e) {
|
||||||
|
// Directory exists
|
||||||
|
}
|
||||||
|
const fileWriteStream = fs.createWriteStream(writePath);
|
||||||
fileWriteStream.write(contents);
|
fileWriteStream.write(contents);
|
||||||
fileWriteStream.end();
|
fileWriteStream.end();
|
||||||
next();
|
next();
|
||||||
|
@ -186,10 +187,11 @@ async function unpackDirectory(directory, options = {}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
extract.on('finish', () => {
|
extract.on('finish', () => {
|
||||||
// all entries read
|
resolve(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReadStream.pipe(extract);
|
fileReadStream.pipe(extract);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -87,7 +87,6 @@ async function packDirectory(directory, options = {}) {
|
||||||
writeFirstEntry(options, tarPack);
|
writeFirstEntry(options, tarPack);
|
||||||
|
|
||||||
await walkAndRun(async (file) => {
|
await walkAndRun(async (file) => {
|
||||||
try{
|
|
||||||
contents = await readFile(path.normalize(file));
|
contents = await readFile(path.normalize(file));
|
||||||
|
|
||||||
// Must be chunked to avoid issues with fixed memory limits.
|
// Must be chunked to avoid issues with fixed memory limits.
|
||||||
|
@ -113,7 +112,7 @@ async function packDirectory(directory, options = {}) {
|
||||||
|
|
||||||
contents = zstd.compressChunks(chunkIterator, contents.length, COMPRESSION_LEVEL);
|
contents = zstd.compressChunks(chunkIterator, contents.length, COMPRESSION_LEVEL);
|
||||||
|
|
||||||
let name = path.relative(packRoot, file);
|
let name = path.relative(packRoot, file).replace('\\', '/');
|
||||||
|
|
||||||
if(/^\.\//.test(name)) {
|
if(/^\.\//.test(name)) {
|
||||||
name = name.slice(2);
|
name = name.slice(2);
|
||||||
|
@ -126,9 +125,8 @@ async function packDirectory(directory, options = {}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
await writeStream(entry, contents);
|
await writeStream(entry, contents);
|
||||||
//console.log(contents)
|
|
||||||
entry.end();
|
entry.end();
|
||||||
}catch (e){console.log(e)}
|
|
||||||
}, directory, packRoot);
|
}, directory, packRoot);
|
||||||
tarPack.finalize();
|
tarPack.finalize();
|
||||||
};
|
};
|
||||||
|
@ -154,6 +152,7 @@ function streamToBuffer(stream) {
|
||||||
|
|
||||||
|
|
||||||
async function unpackDirectory(directory, options = {}) {
|
async function unpackDirectory(directory, options = {}) {
|
||||||
|
return new Promise(async (resolve) => {
|
||||||
if(!fs.existsSync(directory)) {
|
if(!fs.existsSync(directory)) {
|
||||||
fs.mkdirSync(directory);
|
fs.mkdirSync(directory);
|
||||||
}
|
}
|
||||||
|
@ -170,12 +169,14 @@ async function unpackDirectory(directory, options = {}) {
|
||||||
contents = zstd.decompress(contents);
|
contents = zstd.decompress(contents);
|
||||||
|
|
||||||
if(!/^\./.test(header.name)) {
|
if(!/^\./.test(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 });
|
|
||||||
var fileWriteStream = fs.createWriteStream(writePath);
|
try {
|
||||||
|
fs.mkdirSync(path.dirname(writePath), { recursive: true });
|
||||||
|
} catch (e) {
|
||||||
|
// Directory exists
|
||||||
|
}
|
||||||
|
const fileWriteStream = fs.createWriteStream(writePath);
|
||||||
fileWriteStream.write(contents);
|
fileWriteStream.write(contents);
|
||||||
fileWriteStream.end();
|
fileWriteStream.end();
|
||||||
next();
|
next();
|
||||||
|
@ -186,10 +187,11 @@ async function unpackDirectory(directory, options = {}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
extract.on('finish', () => {
|
extract.on('finish', () => {
|
||||||
// all entries read
|
resolve(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReadStream.pipe(extract);
|
fileReadStream.pipe(extract);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue