@@ -240,11 +240,10 @@ for(j = 0; blob.l != 512; ) {
240
240
241
241
242
242
/** Break the file up into sectors */
243
- if ( file . length % ssz !== 0 ) console . error ( "CFB: size " + file . length + " % " + ssz ) ;
244
-
245
243
var nsectors = Math . ceil ( ( file . length - ssz ) / ssz ) ;
246
244
var sectors = [ ] ;
247
- for ( var i = 1 ; i != nsectors + 1 ; ++ i ) sectors [ i - 1 ] = file . slice ( i * ssz , ( i + 1 ) * ssz ) ;
245
+ for ( var i = 1 ; i != nsectors ; ++ i ) sectors [ i - 1 ] = file . slice ( i * ssz , ( i + 1 ) * ssz ) ;
246
+ sectors [ nsectors - 1 ] = file . slice ( nsectors * ssz )
248
247
249
248
/** Chase down the rest of the DIFAT chain to build a comprehensive list
250
249
DIFAT chains by storing the next sector number as the last 32 bytes */
@@ -282,11 +281,11 @@ function get_next_sector(idx) { return get_buffer_u32(idx); }
282
281
var chkd = new Array ( sectors . length ) , sector_list = [ ] ;
283
282
var get_sector = function get_sector ( k ) { return sectors [ k ] ; } ;
284
283
for ( i = 0 ; i != sectors . length ; ++ i ) {
285
- var buf = [ ] ;
286
- if ( chkd [ i ] ) continue ;
287
- for ( j = i ; j <= MAXREGSECT ; buf . push ( j ) , j = get_next_sector ( j ) ) chkd [ j ] = true ;
288
- sector_list [ i ] = { nodes : buf } ;
289
- sector_list [ i ] . data = Array ( buf . map ( get_sector ) ) . toBuffer ( ) ;
284
+ var buf = [ ] , k = ( i + dir_start ) % sectors . length ;
285
+ if ( chkd [ k ] ) continue ;
286
+ for ( j = k ; j <= MAXREGSECT ; buf . push ( j ) , j = get_next_sector ( j ) ) chkd [ j ] = true ;
287
+ sector_list [ k ] = { nodes : buf } ;
288
+ sector_list [ k ] . data = Array ( buf . map ( get_sector ) ) . toBuffer ( ) ;
290
289
}
291
290
sector_list [ dir_start ] . name = "!Directory" ;
292
291
if ( nmfs > 0 && minifat_start !== ENDOFCHAIN ) sector_list [ minifat_start ] . name = "!MiniFAT" ;
@@ -335,7 +334,7 @@ function read_directory(idx) {
335
334
} else {
336
335
o . storage = 'minifat' ;
337
336
w = o . start * mssz ;
338
- if ( minifat_store !== ENDOFCHAIN ) {
337
+ if ( minifat_store !== ENDOFCHAIN && o . start !== ENDOFCHAIN ) {
339
338
o . content = sector_list [ minifat_store ] . data . slice ( w , w + o . size ) ;
340
339
prep_blob ( o . content ) ;
341
340
}
0 commit comments