@@ -15,6 +15,92 @@ describe("XetBlob", () => {
1515 expect ( await blob . slice ( 10 , 22 ) . text ( ) ) . toBe ( "__metadata__" ) ;
1616 } , 30_000 ) ;
1717
18+ it ( "should load the first chunk correctly" , async ( ) => {
19+ let xorbCount = 0 ;
20+ const blob = new XetBlob ( {
21+ repo : {
22+ type : "model" ,
23+ name : "celinah/xet-experiments" ,
24+ } ,
25+ hash : "7b3b6d07673a88cf467e67c1f7edef1a8c268cbf66e9dd9b0366322d4ab56d9b" ,
26+ size : 5_234_139_343 ,
27+ fetch : async ( url , opts ) => {
28+ if ( typeof url === "string" && url . includes ( "/xorbs/" ) ) {
29+ xorbCount ++ ;
30+ }
31+ return fetch ( url , opts ) ;
32+ } ,
33+ } ) ;
34+
35+ const xetDownload = await blob . slice ( 0 , 29928 ) . arrayBuffer ( ) ;
36+ const bridgeDownload = await fetch (
37+ "https://huggingface.co/celinah/xet-experiments/resolve/main/model5GB.safetensors" ,
38+ {
39+ headers : {
40+ Range : "bytes=0-29927" ,
41+ } ,
42+ }
43+ ) . then ( ( res ) => res . arrayBuffer ( ) ) ;
44+
45+ expect ( new Uint8Array ( xetDownload ) ) . toEqual ( new Uint8Array ( bridgeDownload ) ) ;
46+ expect ( xorbCount ) . toBe ( 1 ) ;
47+ } , 30_000 ) ;
48+
49+ it ( "should load just past the first chunk correctly" , async ( ) => {
50+ let xorbCount = 0 ;
51+ const blob = new XetBlob ( {
52+ repo : {
53+ type : "model" ,
54+ name : "celinah/xet-experiments" ,
55+ } ,
56+ hash : "7b3b6d07673a88cf467e67c1f7edef1a8c268cbf66e9dd9b0366322d4ab56d9b" ,
57+ size : 5_234_139_343 ,
58+ fetch : async ( url , opts ) => {
59+ if ( typeof url === "string" && url . includes ( "/xorbs/" ) ) {
60+ xorbCount ++ ;
61+ }
62+ return fetch ( url , opts ) ;
63+ } ,
64+ } ) ;
65+
66+ const xetDownload = await blob . slice ( 0 , 29929 ) . arrayBuffer ( ) ;
67+ const bridgeDownload = await fetch (
68+ "https://huggingface.co/celinah/xet-experiments/resolve/main/model5GB.safetensors" ,
69+ {
70+ headers : {
71+ Range : "bytes=0-29928" ,
72+ } ,
73+ }
74+ ) . then ( ( res ) => res . arrayBuffer ( ) ) ;
75+
76+ expect ( new Uint8Array ( xetDownload ) ) . toEqual ( new Uint8Array ( bridgeDownload ) ) ;
77+ expect ( xetDownload . byteLength ) . toBe ( 29929 ) ;
78+ expect ( xorbCount ) . toBe ( 2 ) ;
79+ } ) ;
80+
81+ it ( "should load correctly when loading far into a chunk range" , async ( ) => {
82+ const blob = new XetBlob ( {
83+ repo : {
84+ type : "model" ,
85+ name : "celinah/xet-experiments" ,
86+ } ,
87+ hash : "7b3b6d07673a88cf467e67c1f7edef1a8c268cbf66e9dd9b0366322d4ab56d9b" ,
88+ size : 5_234_139_343 ,
89+ } ) ;
90+
91+ const xetDownload = await blob . slice ( 10_000_000 , 10_100_000 ) . arrayBuffer ( ) ;
92+ const bridgeDownload = await fetch (
93+ "https://huggingface.co/celinah/xet-experiments/resolve/main/model5GB.safetensors" ,
94+ {
95+ headers : {
96+ Range : "bytes=10000000-10100000" ,
97+ } ,
98+ }
99+ ) . then ( ( res ) => res . arrayBuffer ( ) ) ;
100+
101+ expect ( new Uint8Array ( xetDownload ) ) . toEqual ( new Uint8Array ( bridgeDownload ) ) ;
102+ } ) ;
103+
18104 describe ( "bg4_regoup_bytes" , ( ) => {
19105 it ( "should regroup bytes when the array is %4 length" , ( ) => {
20106 expect ( bg4_regoup_bytes ( new Uint8Array ( [ 1 , 5 , 2 , 6 , 3 , 7 , 4 , 8 ] ) ) ) . toEqual (
0 commit comments