@@ -165,8 +165,10 @@ export async function run(outDir, opts, ctx = {}) {
165165 const throughputStr = humanThroughput ( written , durationMs ) ;
166166 const stats = sink . getStats ?. ( ) || { } ;
167167 const announced = Number . isFinite ( stats . announced ) ? stats . announced : null ;
168+ const hasAnnounced =
169+ announced != null && ( announced > 0 || ( announced === 0 && written === 0 ) ) ;
168170 let announcedValue = "—" ;
169- if ( announced != null ) {
171+ if ( hasAnnounced ) {
170172 const delta = announced - written ;
171173 const deltaSuffix =
172174 delta === 0
@@ -202,7 +204,6 @@ export async function run(outDir, opts, ctx = {}) {
202204 // Return a structured result for programmatic use
203205 return {
204206 bytesWritten : written ,
205- announcedBytes : stats . announced ?? 0 ,
206207 label : stats . label ?? null ,
207208 path : stats . filePath ?? null ,
208209 mode,
@@ -242,7 +243,7 @@ function makeSniffingSink({ outToStdout, outPath, appID, overwrite, onStart, onP
242243 filePath ,
243244 started = false ,
244245 written = 0 ,
245- announced = 0 ,
246+ announced = null ,
246247 label = null ,
247248 desiredName = null ; // <- set by sink.info({ name }) (sanitize it)
248249
@@ -343,50 +344,4 @@ function makeSniffingSink({ outToStdout, outPath, appID, overwrite, onStart, onP
343344
344345 onProgress,
345346 } ;
346- }
347-
348- /**
349- * Dumb sink: write everything to a single file (or stdout).
350- * - If outToStdout is true, all data goes to process.stdout.
351- * - Otherwise, if outPath is given it's treated as a FILE path.
352- * - Otherwise we write ./nt-${appID || 'transfer'}.bin
353- */
354- export function makeSniffingDumbSink ( { outToStdout = false , outPath, appID = "transfer" , overwrite = false , onProgress } = { } ) {
355- let stream ;
356- let filePath = outToStdout ? null : ( outPath
357- ? path . resolve ( outPath )
358- : path . resolve ( process . cwd ( ) , `nt-${ appID } .bin` )
359- ) ;
360- let written = 0 ;
361-
362- if ( outToStdout ) {
363- stream = process . stdout ;
364- } else {
365- // ensure the directory exists
366- fs . mkdirSync ( path . dirname ( filePath ) , { recursive : true } ) ;
367- stream = fs . createWriteStream ( filePath , {
368- flags : overwrite ? "w" : "wx" , // "wx" -> error if exists
369- } ) ;
370- }
371-
372- return {
373- async write ( chunk ) {
374- const buf = chunk instanceof Uint8Array ? chunk : Buffer . from ( chunk ) ;
375- if ( buf . byteLength === 0 ) return ;
376-
377- await new Promise ( ( res , rej ) => stream . write ( buf , ( e ) => ( e ? rej ( e ) : res ( ) ) ) ) ;
378- written += buf . byteLength ;
379- if ( onProgress ) onProgress ( { w : written , t : 0 } ) ;
380- } ,
381-
382- async close ( ) {
383- if ( ! stream || stream === process . stdout ) return ;
384- await new Promise ( ( res ) => stream . end ( res ) ) ;
385- } ,
386-
387- // Optional helper for callers
388- getStats ( ) {
389- return { written, filePath } ;
390- } ,
391- } ;
392- }
347+ }
0 commit comments