import { beforeEach, describe, expect, it } from "bun:test"; import { Readable, Writable } from "stream"; const ABC = new Uint8Array([0x41, 0x42, 0x43]); const DEF = new Uint8Array([0x44, 0x45, 0x46]); const GHI = new Uint8Array([0x47, 0x48, 0x49]); describe("Writable", () => { let called; function logCall(fn, id) { return function () { called[id] = (called[id] || 0) + 1; return fn.apply(this, arguments); }; } beforeEach(() => { called = []; }); it("should perform simple operations", () => { let n = 0; const writable = new Writable({ write: logCall((chunk, encoding, cb) => { expect(chunk instanceof Buffer).toBe(true); if (n++ === 0) { expect(String(chunk)).toBe("ABC"); } else { expect(String(chunk)).toBe("DEF"); } cb(); }, 0), }); writable.write(ABC); writable.end(DEF); expect(called).toEqual([2]); }); it("should pass in Uint8Array in object mode", () => { const writable = new Writable({ objectMode: true, write: logCall((chunk, encoding, cb) => { expect(chunk instanceof Buffer).toBe(false); expect(chunk instanceof Uint8Array).toBe(true); expect(chunk).toStrictEqual(ABC); expect(encoding).toBe("utf8"); cb(); }, 0), }); writable.end(ABC); expect(called).toEqual([1]); }); it("should handle multiple writes carried out via writev()", () => { let callback; const writable = new Writable({ write: logCall((chunk, encoding, cb) => { expect(chunk instanceof Buffer).toBe(true); expect(encoding).toBe("buffer"); expect(String(chunk)).toBe("ABC"); callback = cb; }, 0), writev: logCall((chunks, cb) => { expect(chunks.length).toBe(2); expect(chunks[0].encoding).toBe("buffer"); expect(chunks[1].encoding).toBe("buffer"); expect(chunks[0].chunk + chunks[1].chunk).toBe("DEFGHI"); }, 1), }); writable.write(ABC); writable.write(DEF); writable.end(GHI); callback(); expect(called).toEqual([1, 1]); }); }); describe("Readable", () => { it("should perform simple operations", () => { const readable = new Readable({ read() {}, }); readable.push(DEF); readable.unshift(ABC); const buf = readable.read(); expect(buf instanceof Buffer).toBe(true); expect([...buf]).toEqual([...ABC, ...DEF]); }); it("should work with setEncoding()", () => { const readable = new Readable({ read() {}, }); readable.setEncoding("utf8"); readable.push(DEF); readable.unshift(ABC); const out = readable.read(); expect(out).toBe("ABCDEF"); }); }); ow=1'>helper.rs (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-04-15fix: make watcher's path absolute for notify's MacOS fsevent implementation (...Gravatar Victor C 1-0/+6
2022-03-28chore: bump v0.4.1v0.4.1Gravatar Yujia Qiao 2-2/+2
2022-03-28fix: restart when heartbeat times out (#147)Gravatar Yujia Qiao 1-4/+5
2022-03-25revert(ci): disable incremental compilation (#140) (#144)Gravatar Takayuki Maeda 1-1/+0
2022-03-15ci: disable incremental compilation (#140)Gravatar Takayuki Maeda 1-0/+1
2022-03-09chore: bump v0.4.0v0.4.0Gravatar Yujia Qiao 2-2/+2
2022-03-09chore: bump dependenciesGravatar Yujia Qiao 1-30/+30
2022-03-09chore: make clippy happyGravatar Yujia Qiao 5-7/+7
2022-03-09docs: update README.mdGravatar Yujia Qiao 2-13/+24
2022-03-08ci: run checks for commits on branch devGravatar Yujia Qiao 1-1/+1
2022-03-08feat: application layer heartbeat (#136)Gravatar Yujia Qiao 7-41/+106
2022-03-08feat: support SOCKS5 and HTTP proxy (#135)Gravatar Yujia Qiao 9-28/+152
2022-03-08ci: fix missing artifactsGravatar Yujia Qiao 1-1/+1
2022-03-08ci: fix duplicated checksGravatar Yujia Qiao 1-1/+5
2022-03-08ci: run checks on all branchesGravatar Yujia Qiao 1-5/+1
2022-02-25chore: enable strip in cargoGravatar Yujia Qiao 2-54/+44
2022-02-21chore: bump v0.3.10v0.3.10Gravatar Yujia Qiao 2-143/+229
2022-02-21fix(config_watcher): allow backupcopy for vim (#122)Gravatar mgt 1-4/+10
2022-02-20fix: use unbounded_channelGravatar Yujia Qiao 1-1/+1
2022-02-08test: adapt to openssl 3 (#126)Gravatar Yujia Qiao 2-33/+29
2022-02-07chore: refactor and clean upGravatar Yujia Qiao 2-13/+2
2022-02-07feat: mask out token in logging (#129)Gravatar Yujia Qiao 1-10/+52
2022-02-07fix: use unbounded channels in `config_watcher` (#127)Gravatar Yujia Qiao 1-8/+6
2022-02-07chore: refactorGravatar Yujia Qiao 3-28/+10
2022-02-06fix: set `codegen-units` to 1 (#124)Gravatar Yujia Qiao 1-0/+1
2022-02-06fix: reimplement `retry_notify` with signals (#123)Gravatar Yujia Qiao 5-96/+51
2022-02-06ci: run tests in debug profileGravatar Yujia Qiao 1-3/+3
2022-02-06ci: formatGravatar Yujia Qiao 1-29/+29
2022-02-02test: fix unstable testsGravatar Yujia Qiao 1-5/+3
2022-02-02fix: respect shutdown signal when retry (#121)Gravatar Yujia Qiao 5-31/+104
2022-02-01fix: change some messages to single line styleGravatar Yujia Qiao 1-2/+2
2022-01-26docs: fix a typoGravatar Yujia Qiao 1-1/+1
2022-01-25chore: clean upGravatar Yujia Qiao 1-74/+1
2022-01-25chore: rename docsGravatar Yujia Qiao 4-23/+42