std/encoding/base32_stream_test.ts
Doctor 0f7a71f96b
feat(encoding/unstable): adds streaming versions for hex, base32, base32hex, base64 and base64url (#4915)
* feat(encoding): adds streaming versions of several encoding methods.

Adds streaming methods for:
- Hex
- Base32
- Base64
- Base64Url

* move(encoding): streaming versions to their own modules.

* fix(encoding): jsdoc examples

* fix(encoding): error when chunk's are smaller than the minimum size.

* add(encoding): Base32Hex Encoder/Decoder Streams

* fix(encoding): mod.ts not exporting ./base32hex_stream.ts

* hex stream

* RandomSliceStream

* polish

* base32

* base64hex

* base64

* base64url

* tweak

* fix

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2024-08-22 15:02:36 +10:00

34 lines
1.1 KiB
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { encodeBase32 } from "./base32.ts";
import { Base32DecoderStream, Base32EncoderStream } from "./base32_stream.ts";
import { RandomSliceStream } from "./_random_slice_stream.ts";
import { toText } from "../streams/to_text.ts";
import { concat } from "@std/bytes/concat";
Deno.test("Base32EncoderStream() encodes stream", async () => {
const readable = (await Deno.open("./deno.lock"))
.readable
.pipeThrough(new RandomSliceStream())
.pipeThrough(new Base32EncoderStream());
assertEquals(
await toText(readable),
encodeBase32(await Deno.readFile("./deno.lock")),
);
});
Deno.test("Base32DecoderStream() decodes stream", async () => {
const readable = (await Deno.open("./deno.lock"))
.readable
.pipeThrough(new Base32EncoderStream())
.pipeThrough(new RandomSliceStream())
.pipeThrough(new Base32DecoderStream());
assertEquals(
concat(await Array.fromAsync(readable)),
await Deno.readFile("./deno.lock"),
);
});