deno.land / std@0.173.0 / streams / writer_from_stream_writer_test.ts

writer_from_stream_writer_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";import { writerFromStreamWriter } from "./writer_from_stream_writer.ts";
Deno.test("[streams] writerFromStreamWriter()", async function () { const written: string[] = []; const chunks: string[] = ["hello", "deno", "land"]; const writableStream = new WritableStream({ write(chunk) { const decoder = new TextDecoder(); written.push(decoder.decode(chunk)); }, });
const encoder = new TextEncoder(); const writer = writerFromStreamWriter(writableStream.getWriter());
for (const chunk of chunks) { const n = await writer.write(encoder.encode(chunk)); // stream writers always write all the bytes assertEquals(n, chunk.length); }
assertEquals(written, chunks);});
std

Version Info

Tagged at
a year ago