mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
0f7a71f96b
* 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>
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assertEquals } from "@std/assert";
|
|
import { encodeHex } from "./hex.ts";
|
|
import { HexDecoderStream, HexEncoderStream } from "./hex_stream.ts";
|
|
import { toText } from "@std/streams/to-text";
|
|
import { concat } from "@std/bytes/concat";
|
|
import { RandomSliceStream } from "./_random_slice_stream.ts";
|
|
|
|
Deno.test("HexEncoderStream() encodes stream", async () => {
|
|
const stream = (await Deno.open("./deno.lock"))
|
|
.readable
|
|
.pipeThrough(new RandomSliceStream())
|
|
.pipeThrough(new HexEncoderStream());
|
|
|
|
assertEquals(
|
|
await toText(stream),
|
|
encodeHex(await Deno.readFile("./deno.lock")),
|
|
);
|
|
});
|
|
|
|
Deno.test("HexDecoderStream() decodes stream", async () => {
|
|
const stream = (await Deno.open("./deno.lock"))
|
|
.readable
|
|
.pipeThrough(new HexEncoderStream())
|
|
.pipeThrough(new RandomSliceStream())
|
|
.pipeThrough(new HexDecoderStream());
|
|
|
|
assertEquals(
|
|
concat(await Array.fromAsync(stream)),
|
|
await Deno.readFile("./deno.lock"),
|
|
);
|
|
});
|