Skip to content

Add typings #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
declare namespace CompressJS {
export class Stream {
readByte(): number

read(buf: ByteArray, bufOffset: number, length: number): number

eof(): boolean

seek(pos: number): void

tell(): void

writeByte(byte: number): void;
}

export class BitStream extends Stream {
readBits(n: number): number

writeBitns(n: number, value: number): void;
}

type ByteArray = Buffer | number[] | Uint8Array

type CompressionLevels = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
interface CompressionMethod {
compressFile(input: ByteArray, output?: void | null, compressionLevel?: CompressionLevels | object): number[]
compressFile(input: ByteArray, output?: { writeByte: Stream["writeByte"] }, compressionLevel?: CompressionLevels | object): void

decompressFile(input: ByteArray, output?: void | null): ByteArray
decompressFile(input: ByteArray, output?: { writeByte: Stream["writeByte"] }): void
}

export const BWTC: CompressionMethod;
export const Bzip2: CompressionMethod;
export const Dmc: CompressionMethod;
export const Lzjb: CompressionMethod;
export const LzjbR: CompressionMethod;
export const Lzp3: CompressionMethod;
export const PPM: CompressionMethod;
export const Simple: CompressionMethod;

interface ModelCoder {
encode(symbol: Symbol, ctx?: any): void;
decode(ctx?: any): Symbol;
factory(params: any): (size: number) => this;
}

export const Context1Model: ModelCoder;
export const DefSumModel: ModelCoder;
export const FenwickModel: ModelCoder;
export const MTFModel: ModelCoder;
export const NoModel: ModelCoder;
export const Huffman: ModelCoder;
export const RangeCoder: ModelCoder;
}

export = CompressJS
256 changes: 256 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.3-git",
"author": "C. Scott Ananian",
"description": "pure JavaScript de/compression (bzip2, etc) for node.js, volo, and the browser.",
"types": "main.d.ts",
"keywords": [
"bzip2",
"compression",
Expand All @@ -25,6 +26,7 @@
"commander": "~2.8.1"
},
"devDependencies": {
"@types/node": "^20.11.17",
"mocha": "~2.2.5"
},
"scripts": {
Expand Down