Archive

Stream object

Code examples below

stream.start(callback)

Specify event that will be called when unpacking will be started

stream.progress(callback)

Specify event that will be called every stream.progressInterval ms

This callback will receive the current unpacked data size, total data size, and how much data was unpacked after the previous call

stream.finish(callback)

Specify event that will be called when unpacking will be finished

stream.error(callback)

Specify event that will be called when unpacking can't be started

stream.close(forced)

Close unpacking stream

Archive class

Archive.getType(path)

import { Archive } from '@empathize/framework';

console.log(Archive.getType('my_archive.zip')); // zip

Archive.getInfo(path)

import { Archive } from '@empathize/framework';

Archive.getInfo('my_archive.zip').then((info) => {
    console.log(`Archive type: ${info.type}`); // zip
    console.log(`Unpacked size: ${info.size.unpacked} bytes`);
    console.log(`Compressed size: ${info.size.compressed} bytes`);
    
    console.log("\r\nFiles:");
    
    for (const file of info.files)
    {
        console.log(`Path: ${file.path}`);
        console.log(`Unpacked size: ${file.size.unpacked} bytes`);
        console.log(`Compressed size: ${file.size.compressed} bytes`);
        
        console.log("\r\n");
    }
});

Archive.extract(path, unpackDir)

import { Archive } from '@empathize/framework';

Archive.extract('my_archive.zip', 'path/to/unpack/folder').then((stream) => {
    stream.progressInterval = 1000;
    
    stream.start(() => {
        console.log('Extracting started');
    });
    
    stream.progress((current, total, difference) => {
        console.log(`Extracting progress: ${Math.round(current / total * 100)}%`);
    });
    
    stream.finish(() => {
        console.log('Extracting finished');
    });
});

Archive.closeStreams(forced)

import { Archive } from '@empathize/framework';

Archive.closeStreams().then(() => {
    console.log('All archive extracting streams was closed');
});

Last updated