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
@@ -13,7 +13,7 @@ import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import crypto from 'crypto';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { makeOidbEnvelope } from '../bridge-oidb';
|
||||
import { buildHighwayExtend, fetchHighwaySession, uploadHighwayHttp } from './highway-client';
|
||||
import { BufferChunkSource, buildHighwayExtend, fetchHighwaySession, uploadHighwayHttp } from './highway-client';
|
||||
|
||||
const moduleLog = createLogger('Highway');
|
||||
|
||||
@@ -217,7 +217,7 @@ export async function runNtv2Upload(params: NtV2UploadParams): Promise<NTV2Uploa
|
||||
);
|
||||
log.debug('%s OIDB requires bytes, PUT %d bytes (sub=%s)', label, sub.bytes.length, String(sub.source));
|
||||
const t0 = Date.now();
|
||||
await uploadHighwayHttp(bridge, await getSession(), sub.cmdId, sub.bytes, sub.md5, extend);
|
||||
await uploadHighwayHttp(bridge, await getSession(), sub.cmdId, new BufferChunkSource(sub.bytes), sub.md5, extend);
|
||||
log.debug('%s PUT done in %dms', label, Date.now() - t0);
|
||||
didPut = true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user