@@ -22,10 +22,12 @@ export default class RemoteFile implements GenericFilehandle {
2222 private _stat ?: Stats
2323 private fetchImplementation : Fetcher
2424 private baseHeaders : Record < string , string >
25+ private baseOverrides : Omit < RequestInit , 'headers' >
2526
2627 public constructor ( source : string , opts : FilehandleOptions = { } ) {
2728 this . url = source
2829 this . baseHeaders = opts . headers ?? { }
30+ this . baseOverrides = opts . overrides ?? { }
2931 this . fetchImplementation =
3032 opts . fetch ??
3133 ( ( input : RequestInfo , init ?: RequestInit ) =>
@@ -79,13 +81,11 @@ export default class RemoteFile implements GenericFilehandle {
7981 `read() called with NaN length or position (length=${ length } , position=${ position } ). The index file may be corrupt.` ,
8082 )
8183 }
82- const { headers = { } , signal } = opts
83- if ( length < Infinity ) {
84- headers . range = `bytes=${ position } -${ position + length - 1 } `
85- } else if ( length === Infinity && position !== 0 ) {
86- headers . range = `bytes=${ position } -`
87- }
84+ const { headers = { } , signal, overrides = { } } = opts
85+ headers . range = `bytes=${ position } -${ position + length - 1 } `
8886 const res = await this . fetch ( this . url , {
87+ ...this . baseOverrides ,
88+ ...overrides ,
8989 headers : { ...this . baseHeaders , ...headers } ,
9090 method : 'GET' ,
9191 redirect : 'follow' ,
@@ -143,8 +143,10 @@ export default class RemoteFile implements GenericFilehandle {
143143 ) : Promise < Uint8Array < ArrayBuffer > | string > {
144144 const encoding = typeof options === 'string' ? options : options . encoding
145145 const opts = typeof options === 'string' ? { } : options
146- const { headers = { } , signal } = opts
146+ const { headers = { } , signal, overrides = { } } = opts
147147 const res = await this . fetch ( this . url , {
148+ ...this . baseOverrides ,
149+ ...overrides ,
148150 headers : { ...this . baseHeaders , ...headers } ,
149151 method : 'GET' ,
150152 redirect : 'follow' ,
0 commit comments