mirror of
https://github.com/strapi/strapi.git
synced 2025-09-01 12:53:03 +00:00
feat: add gzip support to readDir
This commit is contained in:
parent
e6f04743d6
commit
cff60542f3
@ -158,27 +158,30 @@ const readDir = async (archive, dir) => {
|
|||||||
* @type {string[]}
|
* @type {string[]}
|
||||||
*/
|
*/
|
||||||
const files = [];
|
const files = [];
|
||||||
|
const isGzipped = archive.endsWith('.tar.gz');
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
pipeline(
|
const streams = [fs.createReadStream(archive)];
|
||||||
[
|
if (isGzipped) {
|
||||||
// Source: Archive stream
|
streams.push(zlib.createGunzip());
|
||||||
fs.createReadStream(archive),
|
}
|
||||||
// Transform: tar parser
|
|
||||||
new tar.Parse({
|
|
||||||
// Match tar entry with the given filename
|
|
||||||
filter: (filePath, entry) => entry.type === 'File' && dir === path.dirname(filePath),
|
|
||||||
// Set outStream to
|
|
||||||
async onentry(entry) {
|
|
||||||
files.push(path.basename(entry.path));
|
|
||||||
|
|
||||||
// Consume the entry anyway to avoid blocking the tar parser
|
// Add the tar parser
|
||||||
await rawCollector(entry);
|
streams.push(
|
||||||
},
|
new tar.Parse({
|
||||||
}),
|
// Match tar entry with the given filename
|
||||||
],
|
filter: (filePath, entry) => entry.type === 'File' && dir === path.dirname(filePath),
|
||||||
(err) => (err ? reject(err) : resolve())
|
// Set outStream to
|
||||||
|
async onentry(entry) {
|
||||||
|
files.push(path.basename(entry.path));
|
||||||
|
|
||||||
|
// Consume the entry anyway to avoid blocking the tar parser
|
||||||
|
await rawCollector(entry);
|
||||||
|
},
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
pipeline(streams, (err) => (err ? reject(err) : resolve()));
|
||||||
});
|
});
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user