Skip to content
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

Start implementing compress/decompress stream classes #1

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
55 changes: 55 additions & 0 deletions stream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type {
Closer,
Reader,
ReaderSync,
Writer,
WriterSync,
} from "https://deno.land/[email protected]/io/types.d.ts";

// size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */
// size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block. */
// size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */
// size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */

export class ZstdCompressor implements Writer, WriterSync, Closer {
constructor(buffer: ArrayBuffer, level: number = 3) {
// const ctx = ZSTD_createCStream();
// // note : since v1.3.0, ZSTD_CStream and ZSTD_CCtx are the same thing.
// // size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value);
// if (isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_compressionLevel, ${level}))) {
// throw new Error(...);
// }
}

async write(p: Uint8Array): Promise<number> {
const res = this.writeSync(p);
return Promise.resolve(res);
}

writeSync(p: Uint8Array): number {
return 0;
}

close(): void {
// ZSTD_freeCStream(ctx);
}
}

export class ZstdDeompressor implements Reader, ReaderSync, Closer {
constructor(buffer: ArrayBuffer) {
// const ctx = ZSTD_createDStream();
}

async read(p: Uint8Array): Promise<number | null> {
const res = this.readSync(p);
return Promise.resolve(res);
}

readSync(p: Uint8Array): number | null {
return 0;
}

close(): void {
// ZSTD_freeDStream(this.ctx);
}
}
10 changes: 10 additions & 0 deletions zstd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,13 @@ export function decompress(
module["_free"](heap, size);
}
}

export function minCompressLevel(): number {
//int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed */
return 0;
}

export function maxCompressLevel(): number {
//int ZSTD_maxCLevel(void); /*!< maximum compression level available */
return 0;
}