Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion encoding/unstable_base32_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class Base32EncoderStream<T extends "string" | "bytes">
* Base32DecoderStream,
* Base32EncoderStream,
* } from "@std/encoding/unstable-base32-stream";
* import { toBytes } from "@std/streams/unstable-to-bytes";
* import { toBytes } from "@std/streams/to-bytes";
*
* const readable = (await Deno.open("./deno.lock"))
* .readable
Expand Down
2 changes: 1 addition & 1 deletion encoding/unstable_base32_stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { assertEquals } from "@std/assert";
import { toText } from "@std/streams";
import { toBytes } from "@std/streams/unstable-to-bytes";
import { toBytes } from "@std/streams/to-bytes";
import { FixedChunkStream } from "@std/streams/unstable-fixed-chunk-stream";
import { encodeBase32 } from "./unstable_base32.ts";
import {
Expand Down
2 changes: 1 addition & 1 deletion encoding/unstable_base64_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class Base64EncoderStream<T extends "string" | "bytes">
* Base64DecoderStream,
* Base64EncoderStream,
* } from "@std/encoding/unstable-base64-stream";
* import { toBytes } from "@std/streams/unstable-to-bytes";
* import { toBytes } from "@std/streams/to-bytes";
*
* const readable = (await Deno.open("./deno.lock"))
* .readable
Expand Down
2 changes: 1 addition & 1 deletion encoding/unstable_base64_stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { assertEquals } from "@std/assert";
import { toText } from "@std/streams";
import { toBytes } from "@std/streams/unstable-to-bytes";
import { toBytes } from "@std/streams/to-bytes";
import { FixedChunkStream } from "@std/streams/unstable-fixed-chunk-stream";
import { encodeBase64 } from "./unstable_base64.ts";
import {
Expand Down
2 changes: 1 addition & 1 deletion encoding/unstable_hex_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class HexEncoderStream<T extends "string" | "bytes">
* HexDecoderStream,
* HexEncoderStream,
* } from "@std/encoding/unstable-hex-stream";
* import { toBytes } from "@std/streams/unstable-to-bytes";
* import { toBytes } from "@std/streams/to-bytes";
*
* const readable = (await Deno.open("./deno.lock"))
* .readable
Expand Down
2 changes: 1 addition & 1 deletion encoding/unstable_hex_stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { assertEquals } from "@std/assert";
import { toText } from "@std/streams";
import { toBytes } from "@std/streams/unstable-to-bytes";
import { toBytes } from "@std/streams/to-bytes";
import { FixedChunkStream } from "@std/streams/unstable-fixed-chunk-stream";
import { encodeHex } from "./unstable_hex.ts";
import { HexDecoderStream, HexEncoderStream } from "./unstable_hex_stream.ts";
Expand Down
2 changes: 1 addition & 1 deletion streams/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"./to-array-buffer": "./to_array_buffer.ts",
"./to-blob": "./to_blob.ts",
"./unstable-to-byte-stream": "./unstable_to_byte_stream.ts",
"./unstable-to-bytes": "./unstable_to_bytes.ts",
"./to-bytes": "./to_bytes.ts",
"./to-json": "./to_json.ts",
"./unstable-to-lines": "./unstable_to_lines.ts",
"./to-text": "./to_text.ts",
Expand Down
1 change: 1 addition & 0 deletions streams/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export * from "./text_delimiter_stream.ts";
export * from "./text_line_stream.ts";
export * from "./to_array_buffer.ts";
export * from "./to_blob.ts";
export * from "./to_bytes.ts";
export * from "./to_json.ts";
export * from "./to_text.ts";
export * from "./to_transform_stream.ts";
Expand Down
4 changes: 1 addition & 3 deletions streams/unstable_to_bytes.ts → streams/to_bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* Converts a {@linkcode ReadableStream} of {@linkcode Uint8Array}s to a
* {@linkcode Uint8Array}. Works the same as {@linkcode Response.bytes}.
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* @param stream A `ReadableStream` of `Uint8Array`s to convert into a `Uint8Array`.
* @returns A `Promise` that resolves to the `Uint8Array`.
*
* @example Basic usage
* ```ts
* import { toBytes } from "@std/streams/unstable-to-bytes";
* import { toBytes } from "@std/streams/to-bytes";
* import { assertEquals } from "@std/assert";
*
* const stream = ReadableStream.from([
Expand Down
35 changes: 35 additions & 0 deletions streams/to_bytes_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2018-2026 the Deno authors. MIT license.

import { assertEquals, assertRejects } from "@std/assert";
import { toBytes } from "./to_bytes.ts";

Deno.test("toBytes() concatenates multiple chunks", async () => {
const stream = ReadableStream.from([
new Uint8Array([1, 2, 3, 4, 5]),
new Uint8Array([6, 7]),
new Uint8Array([8, 9]),
]);

const bytes = await toBytes(stream);
assertEquals(bytes, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]));
});

Deno.test("toBytes() returns empty Uint8Array for empty stream", async () => {
const stream = ReadableStream.from([]);
const bytes = await toBytes(stream);
assertEquals(bytes, new Uint8Array());
});

Deno.test("toBytes() rejects when stream errors", async () => {
const stream = new ReadableStream({
start(controller) {
controller.error(new Error("boom"));
},
});

await assertRejects(
() => toBytes(stream),
Error,
"boom",
);
});
17 changes: 0 additions & 17 deletions streams/unstable_to_bytes_test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tar/untar_stream_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2026 the Deno authors. MIT license.

import { assertEquals, assertRejects } from "@std/assert";
import { toBytes } from "@std/streams/unstable-to-bytes";
import { toBytes } from "@std/streams/to-bytes";
import { TarStream, type TarStreamInput } from "./tar_stream.ts";
import {
type OldStyleFormat,
Expand Down
Loading