Compare commits

..

18 Commits

Author SHA1 Message Date
5ff51ff88d 4.0.17 2023-11-14 10:55:20 +01:00
c578a3fdc1 fix(core): update 2023-11-14 10:55:19 +01:00
ad0352a712 4.0.16 2023-11-13 23:14:39 +01:00
f921338fd6 fix(core): update 2023-11-13 23:14:39 +01:00
614dae5ade 4.0.15 2023-11-13 22:11:25 +01:00
f87359fb97 fix(core): update 2023-11-13 22:11:24 +01:00
21da75c09a 4.0.14 2023-11-13 20:41:52 +01:00
fe49d25765 fix(core): update 2023-11-13 20:41:52 +01:00
5b693c6143 4.0.13 2023-11-13 20:11:10 +01:00
3206738da5 fix(core): update 2023-11-13 20:11:10 +01:00
f709421621 4.0.12 2023-11-13 20:00:29 +01:00
75be95fe45 fix(core): update 2023-11-13 20:00:28 +01:00
1113020e17 4.0.11 2023-11-11 21:06:12 +01:00
adf4bb64ad fix(core): update 2023-11-11 21:06:11 +01:00
0f630382e1 4.0.10 2023-11-11 19:58:20 +01:00
fc09d5aeac fix(core): update 2023-11-11 19:58:19 +01:00
e697730559 4.0.9 2023-11-11 19:55:20 +01:00
0e61bd7c9a fix(core): update 2023-11-11 19:55:19 +01:00
7 changed files with 50 additions and 31 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartarchive",
"version": "4.0.8",
"version": "4.0.17",
"description": "work with archives",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
@ -26,7 +26,7 @@
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/smartrequest": "^2.0.21",
"@push.rocks/smartrx": "^3.0.7",
"@push.rocks/smartstream": "^3.0.14",
"@push.rocks/smartstream": "^3.0.28",
"@push.rocks/smartunique": "^3.0.6",
"@push.rocks/smarturl": "^3.0.7",
"@types/tar-stream": "^3.1.3",

24
pnpm-lock.yaml generated
View File

@ -21,8 +21,8 @@ dependencies:
specifier: ^3.0.7
version: 3.0.7
'@push.rocks/smartstream':
specifier: ^3.0.14
version: 3.0.14
specifier: ^3.0.28
version: 3.0.28
'@push.rocks/smartunique':
specifier: ^3.0.6
version: 3.0.6
@ -597,6 +597,18 @@ packages:
/@push.rocks/isounique@1.0.5:
resolution: {integrity: sha512-Z0BVqZZOCif1THTbIKWMgg0wxCzt9CyBtBBqQJiZ+jJ0KlQFrQHNHrPt81/LXe/L4x0cxWsn0bpL6W5DNSvNLw==}
/@push.rocks/lik@6.0.12:
resolution: {integrity: sha512-/vzlOZ26gCmXZz67LeM2hJ+aNM49Jxvf3FKxLMXHhJwffd3LcV96MYbMfKzKR/za/bh5Itf3a6UjLL5mmN6Pew==}
dependencies:
'@push.rocks/smartdelay': 3.0.5
'@push.rocks/smartmatch': 2.0.0
'@push.rocks/smartpromise': 4.0.3
'@push.rocks/smartrx': 3.0.7
'@push.rocks/smarttime': 4.0.6
'@types/minimatch': 5.1.2
'@types/symbol-tree': 3.2.5
symbol-tree: 3.2.4
/@push.rocks/lik@6.0.5:
resolution: {integrity: sha512-rDSPVknpJDcY3yx4w3lNQfpRkBRuxYVIJKrkiODdH27X0z3+XU4e/iAWKySuLq6H7dAoxSHJDf6BrCO+3Y8kcw==}
dependencies:
@ -735,7 +747,7 @@ packages:
'@push.rocks/smartpath': 5.0.11
'@push.rocks/smartpromise': 4.0.3
'@push.rocks/smartrequest': 2.0.21
'@push.rocks/smartstream': 3.0.14
'@push.rocks/smartstream': 3.0.28
'@types/fs-extra': 11.0.3
'@types/glob': 8.1.0
'@types/js-yaml': 4.0.8
@ -952,9 +964,10 @@ packages:
through2: 4.0.2
dev: true
/@push.rocks/smartstream@3.0.14:
resolution: {integrity: sha512-Z8jysAB/rit9P+vGHwuyNzpD7jGwb5BW+ueYPxWXfcRwQMqhhyGaXyix1CAjJBJ0dOlbKiBoq+tG8Vv8SHzYxA==}
/@push.rocks/smartstream@3.0.28:
resolution: {integrity: sha512-OYKSjjyQj5h9+bxz4cHfUCpbYGHjB3TvseAY/3gWOrli7neGIPg7ycCDiiUYXfYQuPjof9GMzuBsAy4cpiyFNA==}
dependencies:
'@push.rocks/lik': 6.0.12
'@push.rocks/smartpromise': 4.0.3
'@push.rocks/smartrx': 3.0.7
@ -1754,7 +1767,6 @@ packages:
/@types/symbol-tree@3.2.5:
resolution: {integrity: sha512-zXnnyENt1TYQcS21MkPaJCVjfcPq7p7yc5mo5JACuumXp6sly5jnlS0IokHd+xmmuCbx6V7JqkMBpswR+nZAcw==}
dev: true
/@types/tar-stream@3.1.3:
resolution: {integrity: sha512-Zbnx4wpkWBMBSu5CytMbrT5ZpMiF55qgM+EpHzR4yIDu7mv52cej8hTkOc6K+LzpkOAbxwn/m7j3iO+/l42YkQ==}

View File

@ -47,4 +47,4 @@ tap.test('should extract a b2zip', async () => {
);
})
tap.start();
await tap.start();

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartarchive',
version: '4.0.8',
version: '4.0.17',
description: 'work with archives'
}

View File

@ -38,26 +38,27 @@ export function unbzip2Stream() {
}
var outlength = 0;
const decompressAndPush = async (smartDuplexStream: plugins.smartstream.SmartDuplex) => {
const decompressAndPush = async () => {
if (broken) return;
try {
const resultChunk = decompressBlock();
smartDuplexStream.push(resultChunk);
if (resultChunk) {
//console.error('write at', outlength.toString(16));
outlength += resultChunk.length;
}
return resultChunk;
} catch (e) {
console.error(e);
smartDuplexStream.emit('error', e);
broken = true;
return false;
}
};
let counter = 0;
return new plugins.smartstream.SmartDuplex({
objectMode: true,
name: 'bzip2',
debug: true,
highWaterMark: 1,
writeFunction: async function (data, streamTools) {
//console.error('received', data.length,'bytes in', typeof data);
// console.log(`got chunk ${counter++}`)
bufferQueue.push(data);
hasBytes += data.length;
if (bitReader === null) {
@ -67,17 +68,22 @@ export function unbzip2Stream() {
}
while (!broken && hasBytes - bitReader.bytesRead + 1 >= (25000 + 100000 * blockSize || 4)) {
//console.error('decompressing with', hasBytes - bitReader.bytesRead + 1, 'bytes in buffer');
await decompressAndPush(this);
const result = await decompressAndPush();
if (!result) {
continue;
}
// console.log(result.toString());
await streamTools.push(result);
}
},
finalFunction: async function (streamTools) {
//console.error(x,'last compressing with', hasBytes, 'bytes in buffer');
while (!broken && bitReader && hasBytes > bitReader.bytesRead) {
await decompressAndPush(this);
const result = await decompressAndPush();
await streamTools.push(result);
}
if (!broken) {
if (streamCRC !== null) this.emit('error', new Error('input stream ended prematurely'));
this.queue(null);
}
},
});

View File

@ -4,7 +4,7 @@ import * as plugins from './plugins.js';
export interface IAnalyzedResult {
fileType: plugins.fileType.FileTypeResult;
isArchive: boolean;
resultStream: plugins.smartstream.PassThrough;
resultStream: plugins.smartstream.SmartDuplex;
decompressionStream: plugins.stream.Transform | plugins.stream.Duplex | plugins.tarStream.Extract;
}
@ -42,31 +42,30 @@ export class ArchiveAnalyzer {
return this.smartArchiveRef.tarTools.getDecompressionStream(); // replace with your own tar decompression stream
default:
// Handle unsupported formats or no decompression needed
return new plugins.smartstream.PassThrough();
return plugins.smartstream.createPassThrough();
}
}
public getAnalyzedStream() {
let firstRun = true;
const resultStream = new plugins.smartstream.PassThrough();
const resultStream = plugins.smartstream.createPassThrough();
const analyzerstream = new plugins.smartstream.SmartDuplex<Buffer, IAnalyzedResult>({
readableObjectMode: true,
writeFunction: async (chunkArg: Buffer, streamtools) => {
const fileType = await plugins.fileType.fileTypeFromBuffer(chunkArg);
const decompressionStream = await this.getDecompressionStream(fileType?.mime as any);
resultStream.push(chunkArg);
if (firstRun) {
firstRun = false;
const fileType = await plugins.fileType.fileTypeFromBuffer(chunkArg);
const decompressionStream = await this.getDecompressionStream(fileType?.mime as any);
const result: IAnalyzedResult = {
fileType,
isArchive: await this.mimeTypeIsArchive(fileType?.mime),
resultStream,
decompressionStream,
};
streamtools.push(result);
streamtools.push(null);
return null;
await streamtools.push(result);
}
await resultStream.backpressuredPush(chunkArg);
return null;
},
finalFunction: async (tools) => {
resultStream.push(null);

View File

@ -81,7 +81,7 @@ export class SmartArchive {
objectMode: true,
writeFunction: async (chunkArg: plugins.smartfile.StreamFile, streamtools) => {
const done = plugins.smartpromise.defer<void>();
console.log(chunkArg.relativeFilePath);
console.log(chunkArg.relativeFilePath ? chunkArg.relativeFilePath : 'no relative path');
const streamFile = chunkArg;
const readStream = await streamFile.createReadStream();
await plugins.smartfile.fs.ensureDir(targetDir);
@ -142,7 +142,9 @@ export class SmartArchive {
streamFileIntake.push(streamFile);
streamFileIntake.signalEnd();
}
},
}, {
objectMode: true
}
);
archiveStream.pipe(createAnalyzedStream()).pipe(createUnpackStream());