Skip to content

Latest commit

 

History

History
614 lines (479 loc) · 35.2 KB

NODEJSMODULE.md

File metadata and controls

614 lines (479 loc) · 35.2 KB

Node.js native module API reference.

version ⇒ String

The full version string of the library generated on build time. Contains version<major, minor, patch> with optional automatic build number, library type, build date/time, os, compiler, environment, usage, features, etc. and original LZMA SDK version.

streamReadSize ⇔ Number

Read-Write property: receives or updates the size in bytes of the stream's read block per single read request. The lower value requires less amount of allocated memory, but increases the number of read requests and vice versa.

streamWriteSize ⇔ Number

Read-Write property: receives or updates the size in bytes of the stream's write block per single write request. The lower value requires less amount of allocated memory, but increases the number of write requests and vice versa.

ErrorCode

Exported object with exception error codes.

ErrorCode.unknown ⇒ Number

The error type cannot be determined. Might be used as a default value during the initialization or generic, unknown exception was catched during the execution.

ErrorCode.invalidArguments ⇒ Number

Provided function or method arguments are invalid.

ErrorCode.notEnoughMemory ⇒ Number

The required amount of memory can't be alocated or can't instantiate some object.

ErrorCode.io ⇒ Number

File or directory doesn't exists or there are no permissions to perform required action.

ErrorCode.internal ⇒ Number

Any internal errors or exceptions.

Erase

Exported object with types of the erasing content.

Erase.none ⇒ Number

The content will not be erased, i.e. ignored.

Erase.zero ⇒ Number

Erase, rewrite the content with zeros.

FileType

Exported object with types of the file, stream or data buffer.

FileType.sevenZ ⇒ Number

7-zip type. This file type supports multiple archive items, password protected items list of the arhive and password protected content. Supports 'LZMA', 'LZMA2' and 'PPMd' compression methods.

FileType.xz ⇒ Number

XZ type. This file type supports only one arhive item, in a rest it same as 7-zip. Supports only 'LZMA2' compression method which is automatically selected.

FileType.tar ⇒ Number

TAR type. All archive items are combined and stored as one continuous stream without compression and without password protection. For this type, the 'Method' parameter is ignored.

Method

Exported object with compression methods.

Method.LZMA ⇒ Number

Default and general compression method of 7z format.

Method.LZMA2 ⇒ Number

Improved version of LZMA.

Method.PPMd ⇒ Number

Dmitry Shkarin's PPMdH with small changes.

OpenDirMode

Exported object with options for opening directory path. Currently uses for defining behavior of directory iteration.

OpenDirMode.followSymlinks ⇒ Number

Follow the symbolic links.

MultiStreamPartNameFormat

Exported object with options for generating multivolue sub-sctream file name.

MultiStreamPartNameFormat.nameExt00x ⇒ Number

"File"."Extension"."002". The maximum number of parts is 999.

Stat

Exported object with stat info of the path.

Stat.size ⇒ BigInt

Size in bytes.

Stat.creation ⇒ Date

Path creation date.

Stat.lastAccess ⇒ Date

Last path access date.

Stat.lastModification ⇒ Date

Last path modification date.

Path

Exported optional path's string presentation.

new Path()

Constructs empty Path.

new Path([path])

Constructs Path with another path presentation.

  • path {String|Path} Optional path.

Path.toString() ⇒ String

Returns string presentation of the path.

const path = Path('a/b/c');
console.log(`path: ${path}`); // => 'a/b/c'

Path.openDir([options]) ⇒ PathIterator

Opens a directory associated with path for iterating the content.

Path.clear([erase]) ⇒ Path this/self object

Clears the path object's string presentation.

  • erase {Erase} Optional type of erasing of the path data.

Path.set([path]) ⇒ Path this/self object

Set the new path from optional source path.

  • path {[String|Path} Optional source string or path object.

Path.append([path]) ⇒ Path this/self object

Appends path component to path object.

  • path {[String|Path} Optional string or path object.

Path.appending([path]) ⇒ Path

Returns new Path object by appending provided path argument to the receiver.

  • path {[String|Path} Optional string or path object.

Path.appendRandomComponent() ⇒ Path this/self object

Appends random path component to the path object. If path successfully updated, then the updated path doesn't exists in a root directory. The component consists of ASCII characters in range ['a'; 'z'].

Path.appendingRandomComponent() ⇒ Path

Returns new Path object by appending random path component to the receiver.

Path.lastComponent() ⇒ Path

Receives the last component of the path. The result is new instance of the path object representing the last component.

Path.removeLastComponent() ⇒ Path this/self object.

Removes the last component from the path.

Path.removingLastComponent() ⇒ Path

Returns new Path object by removing last path component from the receiver.

Path.remove([skipErrors]) ⇒ Boolean

Physically removes the directory with all content or file associated with the path.

  • skipErrors {Boolean} Optionaly skips errors and continuing removing or stop on first error.

Path.createDir([withIntermediates]) ⇒ Boolean

Creates the directory at specific path.

  • withIntermediates {Boolean} Optionaly create intermediate directories for each component or not.

Path.count ⇒ Number

The number of unicode characters in a path string presentation.

Path.exists ⇒ Number

Checks the path exists. Returns: 1 - file exists, 2 - directory exists, 0 - doesn't exist.

Path.stat ⇒ Stat

Provides the stat info of the path.

Path.readable ⇒ Boolean

Checks the path exists and has read permissions.

Path.writable ⇒ Boolean

Checks the path exists and has write permissions.

Path.readableAndWritable ⇒ Boolean

Checks the path exists and has read-write permissions.

Path.tmpPath ⇒ Path

Provides the path with the platform specific temporary directory for the library. The provided directory path, if such exists, has a read-write permissions.

PathIterator

Path iterator object.

PathIterator.next() ⇒ Boolean

Continue iteration.

PathIterator.close()

Closes iteration.

PathIterator.path ⇒ Path

Recevies the current file or directory path.

PathIterator.component ⇒ Path

Recevies the current file or directory component.

PathIterator.fullPath ⇒ Path

Recevies the current file or directory full path, prefixed with root path.

PathIterator.isDir ⇒ Boolean

Checks the current iterator's path is directory.

Item

The archive item.

new Item()

Constructs empty Item.

new Item([path,[index]])

Constructs the Item with optional path and optional index in the archive.

  • path {String|Path} Optional, associated item's path.
  • index {Number} Optional index of the item in the archive.

Item.toString() ⇒ String

Returns string presentation of the item.

const item = Item('a/b/c', 0);
console.log(`item: ${item}`);

Item.path ⇒ Path

Receives the item's path object.

Item.index ⇒ Number

Receives the item's index inside the archive.

Item.size ⇒ BigInt, ⇐ BigInt|Number

Read-Write property: receives or updates the item's index inside the archive.

Item.packSize ⇒ BigInt, ⇐ BigInt|Number

Read-Write property: receives or updates the packed size in bytes of the item.

Item.crc32 ⇔ Number

Read-Write property: receives or updates the CRC-32 checksum of the items content.

Item.creationDate ⇒ Date, ⇐ Date|Number

Read-Write property: receives or updates the creation date of the item.

Item.accessDate ⇒ Date, ⇐ Date|Number

Read-Write property: receives or updates the access date of the item.

Item.modificationDate ⇒ Date, ⇐ Date|Number

Read-Write property: receives or updates the modification date of the item.

Item.encrypted ⇔ Boolean

Read-Write property: receives or updates the item is encrypted.

Item.isDir ⇔ Boolean

Read-Write property: receives or updates the item is directory or file.

OutStream

The output file stream.

new OutStream()

Constructs the output file stream object for writing to memory.

new OutStream([path])

Constructs the output file stream object for writing to file.

  • path {String|Path} Optional output file path. In case if there is no path argument, the memory stream will be created.

OutStream.erase([type]) ⇒ Boolean

Erases and removes the content of the stream.

  • type {Erase} Optional type of erasing the content.

OutStream.copyContent() ⇒ ArrayBuffer

Copies the content of the stream to a heap memory. The stream must be closed.

OutStream.opened ⇒ Boolean

Checks the output file stream is opened.

OutMultiStream

The output multi volume/part stream.

new OutMultiStream(dirPath, partName, partExtension, format, partSize)

Constructs the output multi stream with directory path, part name, extension, format and part size. All sub-streams are file streams.

  • dirPath {String|Path} The non-empty output directory path.
  • partName {String} The non-empty output file name.
  • partExtension {String} Optional extension.
  • format {MultiStreamPartNameFormat} Format of the result file name part.
  • format {Number} The maximum size in bytes of each out file sub-stream.

new OutMultiStream(partSize)

Constructs the output multi stream object for writing to memory. All sub-streams are memory streams.

  • format {Number} The maximum size in bytes of each out file sub-stream.

OutMultiStream.streams ⇒ Array

Receives array of created OutStream sub-streams. The stream must be closed. If stream is opened, then the list is empty.

InStream

The input file stream.

new InStream(path)

Constructs the input file stream object for reading a file content from path.

  • path {String|Path} File path or path string.

new InStream(fileContent)

Constructs the input file stream object for reading a file content.

  • fileContent {ArrayBuffer} Input file content.

new InStream(array )

Constructs the multi input stream with a list of input streams. The array should not be empty. The order: file.001, file.002, ..., file.XXX

  • array {[ InStream ]} The non-empty array of input streams. Each stream inside the list should also exist.

InStream.erase([type]) ⇒ Boolean

Erases and removes the content of the stream.

  • type {Erase} Optional type of erasing the content.

InStream.opened ⇒ Boolean

Checks the input file stream is opened.

Decoder

The decoder for extracting or testing the archive items.

new Decoder(inStream, fileType)

Constructs the decoder with input file stream and file type.

  • inStream {InStream} The input stream which contains the archive file content. After successful opening, the input stream will be opened as long as a decoder exists.
  • fileType {FileType} The type of the arhive file content.

Decoder.setProgressDelegate([delegate])

Provides the extract or test progress delegate.

  • delegate {function(path{String}, progress{Number})} Optional delegate function to report the progress.

Decoder.setPassword([password])

Provides the archive password for opening, extracting or testing items.

  • password {String} Optional password.

Decoder.open() ⇒ Boolean

Opens the archive.

Decoder.openAsync() ⇒ Promise

Asynchronously opens the archive. The opening progress might be aborted via abort() function. After successful opening, the input stream will be opened as long as a decoder exists.

Decoder.abort()

Aborts opening, extracting or testing process. The aborted decoder is no longer valid.

Decoder.itemAt(index) ⇒ Item

Receives a single archive item at a specific index.

  • index {Number} The index of the item inside the arhive. Must be less than the number of items reported by the count() property.

Decoder.extract(map<Item, OutStream>) ⇒ Boolean

Extracts each archive item to a separate out-stream.

  • map {Map} The item/out-stream map. The key is Item and the value is OutStream.

Decoder.extract(path, [usingItemsFullPath]) ⇒ Boolean

Extracts all archive items to a specific path.

  • path {String|Path} The directory path to extract all items.
  • usingItemsFullPath {Boolean} Optionally extract item using it's full path or only last path component. Default is {true}.

Decoder.extract(array<Item>, path, [usingItemsFullPath]) ⇒ Boolean

Extracts some archive items to a specific path.

  • array {Array} The array of items to extract.
  • usingItemsFullPath {Boolean} Optionally extract item using it's full path or only last path component. Default is {true}.

Decoder.extractAsync(map<Item, OutStream>) ⇒ Promise

Asynchronously extracts each archive item to a separate out-stream. The extracting progress might be aborted via abort() function.

  • map {Map} The item/out-stream map. The key is Item and the value is OutStream.

Decoder.extractAsync(path, [usingItemsFullPath]) ⇒ Promise

Asynchronously extracts all archive items to a specific path. The extracting progress might be aborted via abort() function.

  • path {String|Path} The directory path to extract all items.
  • usingItemsFullPath {Boolean} Optionally extract item using it's full path or only last path component. Default is {true}.

Decoder.extractAsync(array<Item>, path, [usingItemsFullPath]) ⇒ Promise

Asynchronously extracts some archive items to a specific path. The extracting progress might be aborted via abort() function.

  • array {Array} The array of items to extract.
  • usingItemsFullPath {Boolean} Optionally extract item using it's full path or only last path component. Default is {true}.

Decoder.test([array< Item >]) ⇒ Boolean

Tests all or specific archive items.

  • array {Array} Optional array of items to test.

Decoder.testAsync([array< Item >]) ⇒ Promise

Asynchronously tests all or specific archive items. The testing progress might be aborted via abort() function.

  • array {Array} Optional array of items to test.

Decoder.count ⇒ Number

Receives the number of items in archive. The decoder must be opened.

Decoder.items ⇒ Array

Receives array with all archive items. The decoder must be opened.

Encoder

The decoder compressing the archive items.

new Encoder(outStream, fileType, method)

Constructs the encoder with output file stream, file type and method.

  • outStream {OutStream|OutMultiStream} The output file stream to write the archive's file content.
  • fileType {FileType} The type of the arhive file content.
  • method {Method} The compresion method.

Encoder.setProgressDelegate([delegate])

Provides the compression progress delegate.

  • delegate {function(path{String}, progress{Number})} Optional delegate function to report the progress.

Encoder.setPassword([password])

Provides the archive password. This password will be used for encrypting header and the content if such options are enabled and selected type supports password protection. See .shouldEncryptHeader, .shouldEncryptContent properties and FileType enum.

  • password {String} Optional password. Non-string type or zero length password means no password provided.

Encoder.add(path, [openDirMode, [archivePath]])

Adds the physical file or directory path to the encoder. Duplicated path is not allowed.

  • path {String|Path} The file or directory path.
  • openDirMode {OpenDirMode|Array<OpenDirMode>} Optional mode for opening directory in case if path is a directory path.
  • archivePath {String|Path} Optional path of how the item's path will be presented in archive.

Encoder.add(inStream, archivePath)

Adds the file in-stream to the encoder.

  • inStream {InStream} The input file stream to add. Empty stream is not allowed.
  • archivePath {String|Path} The path of how the item's path will be presented in archive. Empty path is not allowed.

Encoder.open() ⇒ Boolean

Opens the archive. Returns false if nothing to compress or encoder aborted or incorrect number of items or number of items greater than supported, otherwise true.

Encoder.openAsync() ⇒ Promise

Asynchronously opens the archive. The testing progress might be aborted via abort() function. Returns false if nothing to compress or encoder aborted or incorrect number of items or number of items greater than supported, otherwise true.

Encoder.abort()

Aborts the opening or compressing process.

Encoder.compress() ⇒ Boolean

Compresses the provided paths and streams.

Encoder.compressAsync() ⇒ Promise

Asynchronously compresses the provided paths and streams.

Encoder.shouldCreateSolidArchive ⇔ Boolean

Read-Write property: receives or updates for a 'solid' archive property. Default true.

Encoder.compressionLevel ⇔ Number

Read-Write property: receives or updates compression level. The level in a range [0; 9].

Encoder.shouldCompressHeader ⇔ Boolean

Read-Write property: should encoder compress the archive header. Default true.

Encoder.shouldCompressHeaderFull ⇔ Boolean

Read-Write property: should encoder fully compress the archive header. Default true.

Encoder.shouldEncryptContent ⇔ Boolean

The encryption will take place only if this option enabled, the type supports password protection and the password has been provided. See .setPassword([password]) function and FileType enum. Read-Write property: should encoder encrypt the content of the archive items. The password will be required to decode/extract archive items.

Encoder.shouldEncryptHeader ⇔ Boolean

The encryption will take place only if this option enabled, the type supports password protection and the password has been provided. See .setPassword([password]) function and FileType enum. Read-Write property: should encoder encrypt the header with the list of archive items. The password will be required to open archive and list the items.

Encoder.shouldStoreCreationDate ⇔ Boolean

Read-Write property: should encoder store the creation date of each item to the header if such available. Default true.

Encoder.shouldStoreAccessDate ⇔ Boolean

Read-Write property: should encoder store the last access date of each item to the header if such available. Default true.

Encoder.shouldStoreModificationDate ⇔ Boolean

Read-Write property: should encoder store the last modification date of each item to the header if such available. Default true.