mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +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>
21 lines
542 B
TypeScript
21 lines
542 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
// This module is browser compatible.
|
|
|
|
type Sliceable = {
|
|
slice(start?: number, end?: number): Sliceable;
|
|
length: number;
|
|
};
|
|
|
|
export class RandomSliceStream<T extends Sliceable>
|
|
extends TransformStream<T, T> {
|
|
constructor() {
|
|
super({
|
|
transform(chunk, controller) {
|
|
const i = Math.floor(Math.random() * chunk.length);
|
|
controller.enqueue(chunk.slice(0, i) as T);
|
|
controller.enqueue(chunk.slice(i) as T);
|
|
},
|
|
});
|
|
}
|
|
}
|