@@ -263,15 +263,25 @@ test('`Switch.file()` read json', async () => {
263
263
264
264
test ( '`Switch.file()` read stream' , async ( ) => {
265
265
const file = Switch . file ( 'romfs:/file.txt' ) ;
266
- const stream = file . stream ( { chunkSize : 3 } ) ;
267
266
const chunks : string [ ] = [ ] ;
268
267
const decoder = new TextDecoder ( ) ;
269
- for await ( const chunk of stream ) {
268
+ for await ( const chunk of file . stream ( { chunkSize : 3 } ) ) {
270
269
chunks . push ( decoder . decode ( chunk ) ) ;
271
270
}
272
271
assert . equal ( chunks , [ 'thi' , 's i' , 's a' , ' te' , 'xt ' , 'fil' , 'e\n' ] ) ;
273
272
} ) ;
274
273
274
+ test ( '`Switch.file()` read stream with slice' , async ( ) => {
275
+ const file = Switch . file ( 'romfs:/file.txt' ) . slice ( 1 , 11 ) ;
276
+ const chunks : string [ ] = [ ] ;
277
+ const decoder = new TextDecoder ( ) ;
278
+ for await ( const chunk of file . stream ( { chunkSize : 3 } ) ) {
279
+ chunks . push ( decoder . decode ( chunk ) ) ;
280
+ }
281
+ assert . equal ( chunks , [ 'his' , ' is' , ' a ' , 't' ] ) ;
282
+ assert . equal ( chunks . join ( '' ) . length , 10 ) ;
283
+ } ) ;
284
+
275
285
test ( '`Switch.file()` read stream throws on ENOENT' , async ( ) => {
276
286
let err : Error | undefined ;
277
287
const file = Switch . file ( 'romfs:/does_not_exist' ) ;
0 commit comments