refactor(highway): introduce ChunkSource for uploadHighwayHttp (phase 1)
Prep for streaming large media uploads from disk instead of buffering the whole file in RAM. Add a `ChunkSource` abstraction — `BufferChunkSource` (in-memory, byte-for-byte the old path) and `FileChunkSource` (disk-backed, reads exact-length chunks via a FileHandle, loops on short reads, throws on unexpected EOF) — and change `uploadHighwayHttp` to consume a `ChunkSource` instead of a `Uint8Array`. The uploader now owns the source and closes it once in `finally` (best-effort; never masks a primary upload error). Pure structural refactor: no streaming is wired yet. All five call sites (pipeline runPuts, group + private file upload, personal + group avatar) wrap their bytes in `BufferChunkSource`, so behavior is unchanged. Adds a byte-oracle test proving FileChunkSource ≡ BufferChunkSource across block boundaries, plus short-read/EOF/empty-input coverage.
This commit is contained in:
11 files changed
+276
-83
No files matched your search
@@ -26,6 +26,7 @@ import type {
|
||||
vi.mock('@snowluma/protocol/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({})),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
BufferChunkSource: class BufferChunkSource { constructor(readonly bytes: Uint8Array) {} },
|
||||
}));
|
||||
|
||||
vi.mock('@snowluma/protocol/highway/utils', () => ({
|
||||
|
||||
@@ -28,6 +28,7 @@ vi.mock('@snowluma/protocol/bridge-oidb', async () => {
|
||||
vi.mock('@snowluma/protocol/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({})),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
BufferChunkSource: class BufferChunkSource { constructor(readonly bytes: Uint8Array) {} },
|
||||
}));
|
||||
|
||||
vi.mock('@snowluma/protocol/highway/utils', () => ({
|
||||
|
||||
Reference in new issue
Block a user