@@ -82,6 +82,7 @@ interface ChunkHeader {
82
82
const CHUNK_HEADER_BYTES = 8 ;
83
83
84
84
// eslint-disable-next-line @typescript-eslint/no-unused-vars
85
+ const debug = ( ...args : unknown [ ] ) => { } ;
85
86
86
87
/**
87
88
* XetBlob is a blob implementation that fetches data directly from the Xet storage
@@ -159,6 +160,7 @@ export class XetBlob extends Blob {
159
160
this . #reconstructionInfoPromise = ( async ( ) => {
160
161
const connParams = await getAccessToken ( this . repoId , this . accessToken , this . fetch , this . hubUrl ) ;
161
162
163
+ // debug(
162
164
// `curl '${connParams.casUrl}/reconstruction/${this.hash}' -H 'Authorization: Bearer ${connParams.accessToken}'`
163
165
// );
164
166
@@ -226,6 +228,7 @@ export class XetBlob extends Blob {
226
228
const termRanges = rangeList . getRanges ( term . range . start , term . range . end ) ;
227
229
228
230
if ( termRanges . every ( ( range ) => range . data ) ) {
231
+ debug ( "all data available for term" , term . hash , readBytesToSkip ) ;
229
232
rangeLoop: for ( const range of termRanges ) {
230
233
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
231
234
for ( let chunk of range . data ! ) {
@@ -241,7 +244,7 @@ export class XetBlob extends Blob {
241
244
chunk = chunk . slice ( 0 , maxBytes - totalBytesRead ) ;
242
245
}
243
246
totalBytesRead += chunk . length ;
244
-
247
+ debug ( "yield" , chunk . length , "bytes" , "total read" , totalBytesRead ) ;
245
248
// The stream consumer can decide to transfer ownership of the chunk, so we need to return a clone
246
249
// if there's more than one range for the same term
247
250
yield range . refCount > 1 ? chunk . slice ( ) : chunk ;
@@ -266,6 +269,10 @@ export class XetBlob extends Blob {
266
269
) ;
267
270
}
268
271
272
+ debug ( "term" , term ) ;
273
+ debug ( "fetchinfo" , fetchInfo ) ;
274
+ debug ( "readBytesToSkip" , readBytesToSkip ) ;
275
+
269
276
let resp = await customFetch ( fetchInfo . url , {
270
277
headers : {
271
278
Range : `bytes=${ fetchInfo . url_range . start } -${ fetchInfo . url_range . end } ` ,
@@ -303,6 +310,8 @@ export class XetBlob extends Blob {
303
310
304
311
done = result . done ;
305
312
313
+ debug ( "read" , result . value ?. length , "bytes" , "total read" , totalBytesRead , "toSkip" , readBytesToSkip ) ;
314
+
306
315
if ( ! result . value ) {
307
316
continue ;
308
317
}
@@ -327,6 +336,8 @@ export class XetBlob extends Blob {
327
336
uncompressed_length : header . getUint8 ( 5 ) | ( header . getUint8 ( 6 ) << 8 ) | ( header . getUint8 ( 7 ) << 16 ) ,
328
337
} ;
329
338
339
+ debug ( "chunk header" , chunkHeader , "to skip" , readBytesToSkip ) ;
340
+
330
341
if ( chunkHeader . version !== 0 ) {
331
342
throw new Error ( `Unsupported chunk version ${ chunkHeader . version } ` ) ;
332
343
}
@@ -387,8 +398,10 @@ export class XetBlob extends Blob {
387
398
}
388
399
389
400
if ( uncompressed . length ) {
401
+ debug ( "yield" , uncompressed . length , "bytes" , result . value . length , "total read" , totalBytesRead , stored ) ;
390
402
totalBytesRead += uncompressed . length ;
391
403
yield stored ? uncompressed . slice ( ) : uncompressed ;
404
+ debug ( "yielded" , uncompressed . length , "bytes" , result . value . length , "total read" , totalBytesRead ) ;
392
405
}
393
406
}
394
407
@@ -397,6 +410,8 @@ export class XetBlob extends Blob {
397
410
}
398
411
}
399
412
413
+ debug ( "done" , done , "total read" , totalBytesRead ) ;
414
+
400
415
// Release the reader
401
416
await reader . cancel ( ) ;
402
417
}
0 commit comments