🚀
Empathize
  • Introduction
  • Installation
  • API
    • Paths API
      • Directories
      • Paths
    • Filesystem API
      • Filesystem
    • Windows API
      • Windows
    • OS API
      • Process
      • Tray
      • IPC
      • Notification
      • Archive
      • Package
    • Network API
      • fetch
      • Domain
      • Downloader
    • Async API
      • promisify
    • Meta classes
      • Cache
      • Configs
      • Debug
  • Building application
Powered by GitBook
On this page
  • Stream object
  • stream.start(callback)
  • stream.progress(callback)
  • stream.finish(callback)
  • stream.error(callback)
  • stream.close(forced)
  • Archive class
  • Archive.getType(path)
  • Archive.getInfo(path)
  • Archive.extract(path, unpackDir)
  • Archive.closeStreams(forced)
  1. API
  2. OS API

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');
});
PreviousNotificationNextPackage

Last updated 3 years ago