mirror of
https://github.com/denoland/std.git
synced 2024-11-21 12:40:03 +00:00
chore(streams): remove redundant constructor examples (#5514)
chore(streams): remove constructor examples
This commit is contained in:
parent
0945b9ef25
commit
2081cafc2d
@ -131,29 +131,6 @@ export class Buffer {
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param ab An optional buffer to use as the initial buffer.
|
||||
*
|
||||
* @example No initial buffer provided
|
||||
* ```ts no-assert
|
||||
* import { Buffer } from "@std/streams/buffer";
|
||||
*
|
||||
* const buf = new Buffer();
|
||||
* ```
|
||||
*
|
||||
* @example With a pre-allocated buffer
|
||||
* ```ts no-assert
|
||||
* import { Buffer } from "@std/streams/buffer";
|
||||
*
|
||||
* const arrayBuffer = new ArrayBuffer(8);
|
||||
* const buf = new Buffer(arrayBuffer);
|
||||
* ```
|
||||
*
|
||||
* @example From Uint8Array
|
||||
* ```ts no-assert
|
||||
* import { Buffer } from "@std/streams/buffer";
|
||||
*
|
||||
* const array = new Uint8Array([0, 1, 2]);
|
||||
* const buf = new Buffer(array.buffer);
|
||||
* ```
|
||||
*/
|
||||
constructor(ab?: ArrayBufferLike | ArrayLike<number>) {
|
||||
this.#buf = ab === undefined ? new Uint8Array(0) : new Uint8Array(ab);
|
||||
|
@ -43,20 +43,6 @@ export class ByteSliceStream extends TransformStream<Uint8Array, Uint8Array> {
|
||||
*
|
||||
* @param start The zero-indexed byte index to start reading from.
|
||||
* @param end The zero-indexed byte index to stop reading at. Inclusive.
|
||||
*
|
||||
* @example No parameters
|
||||
* ```ts no-assert
|
||||
* import { ByteSliceStream } from "@std/streams/byte-slice-stream";
|
||||
*
|
||||
* const byteSliceStream = new ByteSliceStream();
|
||||
* ```
|
||||
*
|
||||
* @example start = 4, end = 11
|
||||
* ```ts no-assert
|
||||
* import { ByteSliceStream } from "@std/streams/byte-slice-stream";
|
||||
*
|
||||
* const byteSliceStream = new ByteSliceStream(4, 11);
|
||||
* ```
|
||||
*/
|
||||
constructor(start = 0, end: number = Infinity) {
|
||||
super({
|
||||
|
@ -74,22 +74,6 @@ export class DelimiterStream extends TransformStream<Uint8Array, Uint8Array> {
|
||||
*
|
||||
* @param delimiter A delimiter to split the stream by.
|
||||
* @param options Options for the delimiter stream.
|
||||
*
|
||||
* @example comma as a delimiter
|
||||
* ```ts no-assert
|
||||
* import { DelimiterStream } from "@std/streams/delimiter-stream";
|
||||
*
|
||||
* const delimiterStream = new DelimiterStream(new TextEncoder().encode(","));
|
||||
* ```
|
||||
*
|
||||
* @example semicolon as a delimiter, and disposition set to `"suffix"`
|
||||
* ```ts no-assert
|
||||
* import { DelimiterStream } from "@std/streams/delimiter-stream";
|
||||
*
|
||||
* const delimiterStream = new DelimiterStream(new TextEncoder().encode(";"), {
|
||||
* disposition: "suffix",
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
constructor(
|
||||
delimiter: Uint8Array,
|
||||
|
@ -101,77 +101,6 @@ export class LimitedBytesTransformStream
|
||||
*
|
||||
* @param size A size limit in bytes.
|
||||
* @param options Options for the stream.
|
||||
*
|
||||
* @example `size` is equal to the total byte length of the chunks
|
||||
* ```ts
|
||||
* import { LimitedBytesTransformStream } from "@std/streams/limited-bytes-transform-stream";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from(["1234", "5678"]);
|
||||
* const transformed = stream.pipeThrough(new TextEncoderStream()).pipeThrough(
|
||||
* new LimitedBytesTransformStream(8),
|
||||
* ).pipeThrough(new TextDecoderStream());
|
||||
*
|
||||
* assertEquals(
|
||||
* await Array.fromAsync(transformed),
|
||||
* ["1234", "5678"],
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @example `size` is less than the total byte length of the chunks, and at the
|
||||
* boundary of the chunks
|
||||
* ```ts
|
||||
* import { LimitedBytesTransformStream } from "@std/streams/limited-bytes-transform-stream";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from(["1234", "5678"]);
|
||||
* const transformed = stream.pipeThrough(new TextEncoderStream()).pipeThrough(
|
||||
* // `4` is the boundary of the chunks
|
||||
* new LimitedBytesTransformStream(4),
|
||||
* ).pipeThrough(new TextDecoderStream());
|
||||
*
|
||||
* assertEquals(
|
||||
* await Array.fromAsync(transformed),
|
||||
* // The first chunk was read, but the second chunk was not
|
||||
* ["1234"],
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @example `size` is less than the total byte length of the chunks, and not at
|
||||
* the boundary of the chunks
|
||||
* ```ts
|
||||
* import { LimitedBytesTransformStream } from "@std/streams/limited-bytes-transform-stream";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from(["1234", "5678"]);
|
||||
* const transformed = stream.pipeThrough(new TextEncoderStream()).pipeThrough(
|
||||
* // `5` is not the boundary of the chunks
|
||||
* new LimitedBytesTransformStream(5),
|
||||
* ).pipeThrough(new TextDecoderStream());
|
||||
*
|
||||
* assertEquals(
|
||||
* await Array.fromAsync(transformed),
|
||||
* // The second chunk was not read because it would exceed the specified size
|
||||
* ["1234"],
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @example Throw error when the total byte length of the chunks exceeds the
|
||||
* specified size
|
||||
*
|
||||
* ```ts
|
||||
* import { LimitedBytesTransformStream } from "@std/streams/limited-bytes-transform-stream";
|
||||
* import { assertRejects } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from(["1234", "5678"]);
|
||||
* const transformed = stream.pipeThrough(new TextEncoderStream()).pipeThrough(
|
||||
* new LimitedBytesTransformStream(5, { error: true }),
|
||||
* ).pipeThrough(new TextDecoderStream());
|
||||
*
|
||||
* await assertRejects(async () => {
|
||||
* await Array.fromAsync(transformed);
|
||||
* }, RangeError);
|
||||
* ```
|
||||
*/
|
||||
constructor(
|
||||
size: number,
|
||||
|
@ -83,59 +83,6 @@ export class LimitedTransformStream<T> extends TransformStream<T, T> {
|
||||
*
|
||||
* @param size The maximum number of chunks to read.
|
||||
* @param options Options for the stream.
|
||||
*
|
||||
* @example `size` is equal to the total number of chunks
|
||||
* ```ts
|
||||
* import { LimitedTransformStream } from "@std/streams/limited-transform-stream";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from(["1234", "5678"]);
|
||||
* const transformed = stream.pipeThrough(
|
||||
* new LimitedTransformStream(2),
|
||||
* );
|
||||
*
|
||||
* // All chunks were read
|
||||
* assertEquals(
|
||||
* await Array.fromAsync(transformed),
|
||||
* ["1234", "5678"],
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @example `size` is less than the total number of chunks
|
||||
* ```ts
|
||||
* import { LimitedTransformStream } from "@std/streams/limited-transform-stream";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from(["1234", "5678"]);
|
||||
* const transformed = stream.pipeThrough(
|
||||
* new LimitedTransformStream(1),
|
||||
* );
|
||||
*
|
||||
* // Only the first chunk was read
|
||||
* assertEquals(
|
||||
* await Array.fromAsync(transformed),
|
||||
* ["1234"],
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @example Throw a {@linkcode RangeError} when the total number of chunks is
|
||||
* about to exceed the specified limit
|
||||
*
|
||||
* Do this by setting `options.error` to `true`.
|
||||
*
|
||||
* ```ts
|
||||
* import { LimitedTransformStream } from "@std/streams/limited-transform-stream";
|
||||
* import { assertRejects } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from(["1234", "5678"]);
|
||||
* const transformed = stream.pipeThrough(
|
||||
* new LimitedTransformStream(1, { error: true }),
|
||||
* );
|
||||
*
|
||||
* await assertRejects(async () => {
|
||||
* await Array.fromAsync(transformed);
|
||||
* }, RangeError);
|
||||
* ```
|
||||
*/
|
||||
constructor(
|
||||
size: number,
|
||||
|
@ -67,22 +67,6 @@ export class TextDelimiterStream extends TransformStream<string, string> {
|
||||
*
|
||||
* @param delimiter A delimiter to split the stream by.
|
||||
* @param options Options for the stream.
|
||||
*
|
||||
* @example Comma as a delimiter
|
||||
* ```ts no-assert
|
||||
* import { TextDelimiterStream } from "@std/streams/text-delimiter-stream";
|
||||
*
|
||||
* const delimiterStream = new TextDelimiterStream(",");
|
||||
* ```
|
||||
*
|
||||
* @example Semicolon as a delimiter, and disposition set to `"suffix"`
|
||||
* ```ts no-assert
|
||||
* import { TextDelimiterStream } from "@std/streams/text-delimiter-stream";
|
||||
*
|
||||
* const delimiterStream = new TextDelimiterStream(",", {
|
||||
* disposition: "suffix",
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
constructor(
|
||||
delimiter: string,
|
||||
|
@ -71,37 +71,6 @@ export class TextLineStream extends TransformStream<string, string> {
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param options Options for the stream.
|
||||
*
|
||||
* @example No parameters
|
||||
* ```ts
|
||||
* import { TextLineStream } from "@std/streams/text-line-stream";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from([
|
||||
* "Hello,\n",
|
||||
* "world!\n",
|
||||
* ]).pipeThrough(new TextLineStream());
|
||||
*
|
||||
* const lines = await Array.fromAsync(stream);
|
||||
*
|
||||
* assertEquals(lines, ["Hello,", "world!"]);
|
||||
* ```
|
||||
*
|
||||
* @example Allow splitting by `\r`
|
||||
*
|
||||
* ```ts
|
||||
* import { TextLineStream } from "@std/streams/text-line-stream";
|
||||
* import { assertEquals } from "@std/assert";
|
||||
*
|
||||
* const stream = ReadableStream.from([
|
||||
* "CR\rLF",
|
||||
* "\nCRLF\r\ndone",
|
||||
* ]).pipeThrough(new TextLineStream({ allowCR: true }));
|
||||
*
|
||||
* const lines = await Array.fromAsync(stream);
|
||||
*
|
||||
* assertEquals(lines, ["CR", "LF", "CRLF", "done"]);
|
||||
* ```
|
||||
*/
|
||||
constructor(options: TextLineStreamOptions = { allowCR: false }) {
|
||||
super({
|
||||
|
Loading…
Reference in New Issue
Block a user