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
Changes from 1 commit
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
Prev Previous commit
Implement ReaderSync & WriterSync
mikroskeem committed Nov 24, 2021
commit 3c1eb01117f492252b2115b2fe257c3520eae564
16 changes: 14 additions & 2 deletions stream.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import type {
Closer,
Reader,
ReaderSync,
Writer,
WriterSync,
} from "https://deno.land/std@0.115.1/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, Closer {
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.
@@ -20,6 +22,11 @@ export class ZstdCompressor implements Writer, Closer {
}

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

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

@@ -28,12 +35,17 @@ export class ZstdCompressor implements Writer, Closer {
}
}

export class ZstdDeompressor implements Reader, Closer {
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;
}