mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 17:49:16 +02:00
Some minor API updates.
This commit is contained in:
parent
24b1603968
commit
cc59935e72
7 changed files with 139 additions and 10 deletions
|
@ -1,6 +1,4 @@
|
|||
|
||||
import { ByteBuffer } from '../io/bytebuffer.js';
|
||||
|
||||
// NOTE: THIS IS A VERY HACKY WORK-IN-PROGRESS! THE API IS NOT FROZEN! USE AT YOUR OWN RISK!
|
||||
|
||||
/**
|
||||
|
@ -10,9 +8,35 @@ import { ByteBuffer } from '../io/bytebuffer.js';
|
|||
* @property {ArrayBuffer} fileData The bytes of the file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
export const ZipCompressionMethod = {
|
||||
STORE: 0, // Default.
|
||||
// DEFLATE: 8,
|
||||
};
|
||||
|
||||
// export const DeflateCompressionMethod = {
|
||||
// NO_COMPRESSION: 0,
|
||||
// COMPRESSION_FIXED_HUFFMAN: 1,
|
||||
// COMPRESSION_DYNAMIC_HUFFMAN: 2,
|
||||
// }
|
||||
|
||||
/**
|
||||
* Data elements are packed into bytes in order of increasing bit number within the byte,
|
||||
i.e., starting with the least-significant bit of the byte.
|
||||
* Data elements other than Huffman codes are packed starting with the least-significant bit of the
|
||||
data element.
|
||||
* Huffman codes are packed starting with the most-significant bit of the code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef CompressorOptions
|
||||
* @property {string} pathToBitJS A string indicating where the BitJS files are located.
|
||||
* @property {ZipCompressionMethod} zipCompressionMethod
|
||||
* @property {DeflateCompressionMethod=} deflateCompressionMethod Only present if
|
||||
* zipCompressionMethod is set to DEFLATE.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -30,6 +54,7 @@ export const CompressStatus = {
|
|||
/**
|
||||
* A thing that zips files.
|
||||
* NOTE: THIS IS A VERY HACKY WORK-IN-PROGRESS! THE API IS NOT FROZEN! USE AT YOUR OWN RISK!
|
||||
* TODO: Make a streaming / event-driven API.
|
||||
*/
|
||||
export class Zipper {
|
||||
/**
|
||||
|
@ -43,6 +68,12 @@ export class Zipper {
|
|||
*/
|
||||
this.pathToBitJS = options.pathToBitJS || '/';
|
||||
|
||||
/**
|
||||
* @type {ZipCompressionMethod}
|
||||
* @private
|
||||
*/
|
||||
this.zipCompressionMethod = options.zipCompressionMethod || ZipCompressionMethod.STORE;
|
||||
|
||||
/**
|
||||
* Private web worker initialized during start().
|
||||
* @type {Worker}
|
||||
|
@ -80,9 +111,13 @@ export class Zipper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Send in a set of files to be compressed. Set isLastFile to true if no more files are to added
|
||||
* at some future state. The Promise will not resolve until isLastFile is set to true either in
|
||||
* this method or in appendFiles().
|
||||
* @param {FileInfo[]} files
|
||||
* @param {boolean} isLastFile
|
||||
* @returns {Promise<Uint8Array>} A Promise that contains the entire zipped archive.
|
||||
* @returns {Promise<Uint8Array>} A Promise that will contain the entire zipped archive as an array
|
||||
* of bytes.
|
||||
*/
|
||||
start(files, isLastFile) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue