generic-filehandle2 2.0.17 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import type { FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
1
+ import type { BufferEncoding, FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
2
2
  /**
3
3
  * Blob of binary data fetched from a local file (with FileReader).
4
4
  *
package/dist/blobFile.js CHANGED
@@ -16,9 +16,7 @@ class BlobFile {
16
16
  if (!length) {
17
17
  return new Uint8Array(0);
18
18
  }
19
- const start = position;
20
- const end = start + length;
21
- const slice = this.blob.slice(start, end);
19
+ const slice = this.blob.slice(position, position + length);
22
20
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
23
21
  return slice.bytes
24
22
  ? slice.bytes()
@@ -39,11 +37,11 @@ class BlobFile {
39
37
  : new Uint8Array(await this.blob.arrayBuffer());
40
38
  }
41
39
  }
42
- async stat() {
43
- return { size: this.blob.size };
40
+ stat() {
41
+ return Promise.resolve({ size: this.blob.size });
44
42
  }
45
- async close() {
46
- return;
43
+ close() {
44
+ return Promise.resolve();
47
45
  }
48
46
  }
49
47
  exports.default = BlobFile;
@@ -1 +1 @@
1
- {"version":3,"file":"blobFile.js","sourceRoot":"","sources":["../src/blobFile.ts"],"names":[],"mappings":";;AAMA;;;;;GAKG;AACH,MAAqB,QAAQ;IAG3B,YAAmB,IAAU;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,KAAK,CAAC,IAAI,CACf,MAAc,EACd,QAAQ,GAAG,CAAC;QAEZ,4EAA4E;QAC5E,sDAAsD;QACtD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;QAC1B,CAAC;QAED,MAAM,KAAK,GAAG,QAAQ,CAAA;QACtB,MAAM,GAAG,GAAG,KAAK,GAAG,MAAM,C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ACV,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;CACF;AAzDD,2BAyDC"}
@@ -1,22 +1,14 @@
1
+ export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'utf-16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
1
2
  export type Fetcher = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
2
3
  export interface FilehandleOptions {
3
- /**
4
- * optional AbortSignal object for aborting the request
5
- */
6
4
  signal?: AbortSignal;
7
- headers?: any;
8
- overrides?: any;
5
+ headers?: Record<string, string>;
6
+ overrides?: Omit<RequestInit, 'headers'>;
9
7
  encoding?: BufferEncoding;
10
- /**
11
- * fetch function to use for HTTP requests. defaults to environment's
12
- * global fetch. if there is no global fetch, and a fetch function is not provided,
13
- * throws an error.
14
- */
15
8
  fetch?: Fetcher;
16
9
  }
17
10
  export interface Stats {
18
11
  size: number;
19
- [key: string]: any;
20
12
  }
21
13
  export interface GenericFilehandle {
22
14
  read(length: number, position: number, opts?: FilehandleOptions): Promise<Uint8Array<ArrayBuffer>>;
@@ -30,7 +22,7 @@ export interface GenericFilehandle {
30
22
  }): Promise<string>;
31
23
  readFile<T extends BufferEncoding>(options: Omit<FilehandleOptions, 'encoding'> & {
32
24
  encoding: T;
33
- }): T extends BufferEncoding ? Promise<Uint8Array<ArrayBuffer>> : Promise<Uint8Array<ArrayBuffer> | string>;
25
+ }): T extends BufferEncoding ? Promise<string> : Promise<Uint8Array<ArrayBuffer>>;
34
26
  stat(): Promise<Stats>;
35
27
  close(): Promise<void>;
36
28
  }
package/dist/index.d.ts CHANGED
@@ -2,4 +2,3 @@ export * from './filehandle.ts';
2
2
  export { default as BlobFile } from './blobFile.ts';
3
3
  export { default as RemoteFile } from './remoteFile.ts';
4
4
  export { default as LocalFile } from './localFile.ts';
5
- export { type GenericFilehandle } from './filehandle.ts';
@@ -1,7 +1,7 @@
1
- import type { FilehandleOptions, GenericFilehandle } from './filehandle.ts';
1
+ import type { BufferEncoding, FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
2
2
  export default class LocalFile implements GenericFilehandle {
3
3
  private filename;
4
- constructor(source: string, _opts?: FilehandleOptions);
4
+ constructor(source: string);
5
5
  read(length: number, position?: number): Promise<Uint8Array<ArrayBuffer>>;
6
6
  readFile(): Promise<Uint8Array<ArrayBuffer>>;
7
7
  readFile(options: BufferEncoding): Promise<string>;
@@ -11,6 +11,9 @@ export default class LocalFile implements GenericFilehandle {
11
11
  readFile<T extends BufferEncoding>(options: Omit<FilehandleOptions, 'encoding'> & {
12
12
  encoding: T;
13
13
  }): Promise<string>;
14
- stat(): Promise<import("fs").Stats>;
14
+ readFile<T extends BufferEncoding>(options: Omit<FilehandleOptions, 'encoding'> & {
15
+ encoding: T;
16
+ }): T extends BufferEncoding ? Promise<string> : Promise<Uint8Array<ArrayBuffer>>;
17
+ stat(): Promise<Stats>;
15
18
  close(): Promise<void>;
16
19
  }
package/dist/localFile.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const promises_1 = require("fs/promises");
4
4
  class LocalFile {
5
- constructor(source, _opts = {}) {
5
+ constructor(source) {
6
6
  this.filename = source;
7
7
  }
8
8
  async read(length, position = 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"localFile.js","sourceRoot":"","sources":["../src/localFile.ts"],"names":[],"mappings":";;AAAA,0CAAkD;AAIlD,MAAqB,SAAS;IAG5B,YAAmB,MAAc,EAAE,QAA2B,EAAE;QAC9D,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAA;IACxB,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,QAAQ,GAAG,CAAC;QAC5C,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;YACjB,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;QAC1B,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAA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G,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;QAClC,IAAI,EAAE,CAAA;QACN,IAAI,CAAC;YACH,EAAE,GAAG,MAAM,IAAA,eAAI,EAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;YACnC,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;YACnD,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;QAC9C,CAAC;gBAAS,CAAC;YACT,IAAI,EAAE,EAAE,CAAC;gBACP,IAAI,CAAC;oBACH,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;gBAClB,CAAC;gBAAC,MAAM,CAAC;oBACP,sEAAsE;oBACtE,oDAAoD;gBACtD,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAiBM,KAAK,CAAC,QAAQ,CACnB,OAA4C;QAE5C,OAAO,IAAA,mBAAQ,EAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACzC,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,OAAO,IAAA,eAAI,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5B,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,gBAAgB;IAClB,CAAC;CACF;AAzDD,4BAyDC"}
@@ -1,8 +1,9 @@
1
- import type { FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
1
+ import type { BufferEncoding, FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
2
2
  export default class RemoteFile implements GenericFilehandle {
3
3
  protected url: string;
4
4
  private _stat?;
5
5
  private fetchImplementation;
6
+ private baseHeaders;
6
7
  private baseOverrides;
7
8
  constructor(source: string, opts?: FilehandleOptions);
8
9
  fetch(input: RequestInfo, init: RequestInit | undefined): Promise<Response>;
@@ -17,7 +18,7 @@ export default class RemoteFile implements GenericFilehandle {
17
18
  }): Promise<string>;
18
19
  readFile<T extends BufferEncoding>(options: Omit<FilehandleOptions, 'encoding'> & {
19
20
  encoding: T;
20
- }): T extends BufferEncoding ? Promise<Uint8Array<ArrayBuffer>> : Promise<Uint8Array<ArrayBuffer> | string>;
21
+ }): T extends BufferEncoding ? Promise<string> : Promise<Uint8Array<ArrayBuffer>>;
21
22
  stat(): Promise<Stats>;
22
23
  close(): Promise<void>;
23
24
  }
@@ -1,29 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function getMessage(e) {
4
- const r = typeof e === 'object' && e !== null && 'message' in e
4
+ const r = typeof e === 'object' &&
5
+ e !== null &&
6
+ 'message' in e &&
7
+ typeof e.message === 'string'
5
8
  ? e.message
6
9
  : `${e}`;
7
10
  return r.replace(/\.$/, '');
8
11
  }
9
12
  class RemoteFile {
10
13
  constructor(source, opts = {}) {
11
- this.baseOverrides = {};
12
14
  this.url = source;
13
- const fetch = opts.fetch || globalThis.fetch.bind(globalThis);
14
- if (opts.overrides) {
15
- this.baseOverrides = opts.overrides;
16
- }
17
- this.fetchImplementation = fetch;
15
+ this.baseHeaders = opts.headers ?? {};
16
+ this.baseOverrides = opts.overrides ?? {};
17
+ this.fetchImplementation =
18
+ opts.fetch ??
19
+ ((input, init) => globalThis.fetch(input, init));
18
20
  }
19
21
  async fetch(input, init) {
22
+ const wrapError = (e) => new Error(`${getMessage(e)} fetching ${input}`, { cause: e });
20
23
  let response;
21
24
  try {
22
25
  response = await this.fetchImplementation(input, init);
23
26
  }
24
27
  catch (e) {
25
28
  if (`${e}`.includes('Failed to fetch')) {
26
- // refetch to to help work around a chrome bug (discussed in
29
+ // refetch to help work around a chrome bug (discussed in
27
30
  // generic-filehandle issue #72) in which the chrome cache returns a
28
31
  // CORS error for content in its cache. see also
29
32
  // https://github.com/GMOD/jbrowse-components/pull/1511
@@ -35,11 +38,11 @@ class RemoteFile {
35
38
  });
36
39
  }
37
40
  catch (e) {
38
- throw new Error(`${getMessage(e)} fetching ${input}`, { cause: e });
41
+ throw wrapError(e);
39
42
  }
40
43
  }
41
44
  else {
42
- throw new Error(`${getMessage(e)} fetching ${input}`, { cause: e });
45
+ throw wrapError(e);
43
46
  }
44
47
  }
45
48
  return response;
@@ -48,21 +51,15 @@ class RemoteFile {
48
51
  if (length === 0) {
49
52
  return new Uint8Array(0);
50
53
  }
51
- const { headers = {}, signal, overrides = {} } = opts;
52
- if (length < Infinity) {
53
- headers.range = `bytes=${position}-${position + length - 1}`;
54
- }
55
- else if (length === Infinity && position !== 0) {
56
- headers.range = `bytes=${position}-`;
54
+ if (Number.isNaN(length) || Number.isNaN(position)) {
55
+ throw new TypeError(`read() called with NaN length or position (length=${length}, position=${position}). The index file may be corrupt.`);
57
56
  }
57
+ const { headers = {}, signal, overrides = {} } = opts;
58
+ headers.range = `bytes=${position}-${position + length - 1}`;
58
59
  const res = await this.fetch(this.url, {
59
60
  ...this.baseOverrides,
60
61
  ...overrides,
61
- headers: {
62
- ...this.baseOverrides.headers,
63
- ...overrides.headers,
64
- ...headers,
65
- },
62
+ headers: { ...this.baseHeaders, ...headers },
66
63
  method: 'GET',
67
64
  redirect: 'follow',
68
65
  mode: 'cors',
@@ -74,7 +71,7 @@ class RemoteFile {
74
71
  if ((res.status === 200 && position === 0) || res.status === 206) {
75
72
  // try to parse out the size of the remote file
76
73
  const contentRange = res.headers.get('content-range');
77
- const sizeMatch = /\/(\d+)$/.exec(contentRange || '');
74
+ const sizeMatch = /\/(\d+)$/.exec(contentRange ?? '');
78
75
  if (sizeMatch?.[1]) {
79
76
  this._stat = {
80
77
  size: parseInt(sizeMatch[1], 10),
@@ -93,32 +90,19 @@ class RemoteFile {
93
90
  : `HTTP ${res.status} fetching ${this.url}`);
94
91
  }
95
92
  async readFile(options = {}) {
96
- let encoding;
97
- let opts;
98
- if (typeof options === 'string') {
99
- encoding = options;
100
- opts = {};
101
- }
102
- else {
103
- encoding = options.encoding;
104
- const { encoding: _, ...rest } = options;
105
- opts = rest;
106
- }
93
+ const encoding = typeof options === 'string' ? options : options.encoding;
94
+ const opts = typeof options === 'string' ? {} : options;
107
95
  const { headers = {}, signal, overrides = {} } = opts;
108
96
  const res = await this.fetch(this.url, {
109
97
  ...this.baseOverrides,
110
98
  ...overrides,
111
- headers: {
112
- ...this.baseOverrides.headers,
113
- ...overrides.headers,
114
- ...headers,
115
- },
99
+ headers: { ...this.baseHeaders, ...headers },
116
100
  method: 'GET',
117
101
  redirect: 'follow',
118
102
  mode: 'cors',
119
103
  signal,
120
104
  });
121
- if (res.status !== 200) {
105
+ if (!res.ok) {
122
106
  throw new Error(`HTTP ${res.status} fetching ${this.url}`);
123
107
  }
124
108
  if (encoding === 'utf8') {
@@ -142,8 +126,8 @@ class RemoteFile {
142
126
  }
143
127
  return this._stat;
144
128
  }
145
- async close() {
146
- return;
129
+ close() {
130
+ return Promise.resolve();
147
131
  }
148
132
  }
149
133
  exports.default = RemoteFile;
@@ -1 +1 @@
1
- {"version":3,"file":"remoteFile.js","sourceRoot":"","sources":["../src/remoteFile.ts"],"names":[],"mappings":";;AAOA,SAAS,UAAU,CAAC,CAAU;IAC5B,MAAM,CAAC,GACL,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,SAAS,IAAI,CAAC;QACnD,CAAC,CAAE,CAAC,CAAC,OAAkB;QACvB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAA;IACZ,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC7B,CAAC;AAED,MAAqB,UAAU;IAM7B,YAAmB,MAAc,EAAE,OAA0B,EAAE;QAFvD,kBAAa,GAAQ,EAAE,CAAA;QAG7B,IAAI,CAAC,GAAG,GAAG,MAAM,CAAA;QACjB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC7D,IAAI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;YACN,uEAAuE;YACvE,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;QAC1E,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;YACtB,uEAAuE;YACvE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,uCAAuC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;YACpE,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAEM,KAAK;QACV,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;CACF;AAnKD,6BAmKC"}
package/esm/blobFile.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
1
+ import type { BufferEncoding, FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
2
2
  /**
3
3
  * Blob of binary data fetched from a local file (with FileReader).
4
4
  *
package/esm/blobFile.js CHANGED
@@ -14,9 +14,7 @@ export default class BlobFile {
14
14
  if (!length) {
15
15
  return new Uint8Array(0);
16
16
  }
17
- const start = position;
18
- const end = start + length;
19
- const slice = this.blob.slice(start, end);
17
+ const slice = this.blob.slice(position, position + length);
20
18
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
21
19
  return slice.bytes
22
20
  ? slice.bytes()
@@ -37,11 +35,11 @@ export default class BlobFile {
37
35
  : new Uint8Array(await this.blob.arrayBuffer());
38
36
  }
39
37
  }
40
- async stat() {
41
- return { size: this.blob.size };
38
+ stat() {
39
+ return Promise.resolve({ size: this.blob.size });
42
40
  }
43
- async close() {
44
- return;
41
+ close() {
42
+ return Promise.resolve();
45
43
  }
46
44
  }
47
45
  //# sourceMappingURL=blobFile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"blobFile.js","sourceRoot":"","sources":["../src/blobFile.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAG3B,YAAmB,IAAU;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,KAAK,CAAC,IAAI,CACf,MAAc,EACd,QAAQ,GAAG,CAAC;QAEZ,4EAA4E;QAC5E,sDAAsD;QACtD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;QAC1B,CAAC;QAED,MAAM,KAAK,GAAG,QAAQ,CAAA;QACtB,MAAM,GAAG,GAAG,KAAK,GAAG,MAAM,CAAA;QAE1B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QACzC,uEAAuE;QACvE,OAAO,KAAK,CAAC,KAAK;YAChB,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE;YACf,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;IAC/C,CAAC;IAYM,KAAK,CAAC,QAAQ,CACnB,OAA4C;QAE5C,MAAM,QAAQ,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAA;QAC1E,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QACzB,CAAC;aAAM,IAAI,QAAQ,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAA;QACtD,CAAC;aAAM,CAAC;YACN,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MAAM,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QACzB,CAAC;aAAM,IAAI,QAAQ,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAA;QACtD,CAAC;aAAM,CAAC;YACN,uEAAuE;YACvE,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK;gBACpB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;gBACnB,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAEM,IAAI;QACT,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IAClD,CAAC;IAEM,KAAK;QACV,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;CACF"}
@@ -1,22 +1,14 @@
1
+ export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'utf-16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
1
2
  export type Fetcher = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
2
3
  export interface FilehandleOptions {
3
- /**
4
- * optional AbortSignal object for aborting the request
5
- */
6
4
  signal?: AbortSignal;
7
- headers?: any;
8
- overrides?: any;
5
+ headers?: Record<string, string>;
6
+ overrides?: Omit<RequestInit, 'headers'>;
9
7
  encoding?: BufferEncoding;
10
- /**
11
- * fetch function to use for HTTP requests. defaults to environment's
12
- * global fetch. if there is no global fetch, and a fetch function is not provided,
13
- * throws an error.
14
- */
15
8
  fetch?: Fetcher;
16
9
  }
17
10
  export interface Stats {
18
11
  size: number;
19
- [key: string]: any;
20
12
  }
21
13
  export interface GenericFilehandle {
22
14
  read(length: number, position: number, opts?: FilehandleOptions): Promise<Uint8Array<ArrayBuffer>>;
@@ -30,7 +22,7 @@ export interface GenericFilehandle {
30
22
  }): Promise<string>;
31
23
  readFile<T extends BufferEncoding>(options: Omit<FilehandleOptions, 'encoding'> & {
32
24
  encoding: T;
33
- }): T extends BufferEncoding ? Promise<Uint8Array<ArrayBuffer>> : Promise<Uint8Array<ArrayBuffer> | string>;
25
+ }): T extends BufferEncoding ? Promise<string> : Promise<Uint8Array<ArrayBuffer>>;
34
26
  stat(): Promise<Stats>;
35
27
  close(): Promise<void>;
36
28
  }
package/esm/index.d.ts CHANGED
@@ -2,4 +2,3 @@ export * from './filehandle.ts';
2
2
  export { default as BlobFile } from './blobFile.ts';
3
3
  export { default as RemoteFile } from './remoteFile.ts';
4
4
  export { default as LocalFile } from './localFile.ts';
5
- export { type GenericFilehandle } from './filehandle.ts';
@@ -1,7 +1,7 @@
1
- import type { FilehandleOptions, GenericFilehandle } from './filehandle.ts';
1
+ import type { BufferEncoding, FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
2
2
  export default class LocalFile implements GenericFilehandle {
3
3
  private filename;
4
- constructor(source: string, _opts?: FilehandleOptions);
4
+ constructor(source: string);
5
5
  read(length: number, position?: number): Promise<Uint8Array<ArrayBuffer>>;
6
6
  readFile(): Promise<Uint8Array<ArrayBuffer>>;
7
7
  readFile(options: BufferEncoding): Promise<string>;
@@ -11,6 +11,9 @@ export default class LocalFile implements GenericFilehandle {
11
11
  readFile<T extends BufferEncoding>(options: Omit<FilehandleOptions, 'encoding'> & {
12
12
  encoding: T;
13
13
  }): Promise<string>;
14
- stat(): Promise<import("fs").Stats>;
14
+ readFile<T extends BufferEncoding>(options: Omit<FilehandleOptions, 'encoding'> & {
15
+ encoding: T;
16
+ }): T extends BufferEncoding ? Promise<string> : Promise<Uint8Array<ArrayBuffer>>;
17
+ stat(): Promise<Stats>;
15
18
  close(): Promise<void>;
16
19
  }
package/esm/localFile.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { open, readFile, stat } from 'fs/promises';
2
2
  export default class LocalFile {
3
- constructor(source, _opts = {}) {
3
+ constructor(source) {
4
4
  this.filename = source;
5
5
  }
6
6
  async read(length, position = 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"localFile.js","sourceRoot":"","sources":["../src/localFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAIlD,MAAM,CAAC,OAAO,OAAO,SAAS;IAG5B,YAAmB,MAAc,EAAE,QAA2B,EAAE;QAC9D,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAA;IACxB,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,QAAQ,GAAG,CAAC;QAC5C,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;YACjB,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;QAC1B,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;QAClC,IAAI,EAAE,CAAA;QACN,IAAI,CAAC;YACH,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;YACnC,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;YACnD,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;QAC9C,CAAC;gBAAS,CAAC;YACT,IAAI,EAAE,EAAE,CAAC;gBACP,IAAI,CAAC;oBACH,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;gBAClB,CAAC;gBAAC,MAAM,CAAC;oBACP,sEAAsE;oBACtE,oDAAoD;gBACtD,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAYM,KAAK,CAAC,QAAQ,CACnB,OAA4C;QAE5C,OAAO,QAAQ,CAAC,IAA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AK,CAAC,QAAQ,CACnB,OAA4C;QAE5C,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACzC,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5B,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,gBAAgB;IAClB,CAAC;CACF"}
@@ -1,8 +1,9 @@
1
- import type { FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
1
+ import type { BufferEncoding, FilehandleOptions, GenericFilehandle, Stats } from './filehandle.ts';
2
2
  export default class RemoteFile implements GenericFilehandle {
3
3
  protected url: string;
4
4
  private _stat?;
5
5
  private fetchImplementation;
6
+ private baseHeaders;
6
7
  private baseOverrides;
7
8
  constructor(source: string, opts?: FilehandleOptions);
8
9
  fetch(input: RequestInfo, init: RequestInit | undefined): Promise<Response>;
@@ -17,7 +18,7 @@ export default class RemoteFile implements GenericFilehandle {
17
18
  }): Promise<string>;
18
19
  readFile<T extends BufferEncoding>(options: Omit<FilehandleOptions, 'encoding'> & {
19
20
  encoding: T;
20
- }): T extends BufferEncoding ? Promise<Uint8Array<ArrayBuffer>> : Promise<Uint8Array<ArrayBuffer> | string>;
21
+ }): T extends BufferEncoding ? Promise<string> : Promise<Uint8Array<ArrayBuffer>>;
21
22
  stat(): Promise<Stats>;
22
23
  close(): Promise<void>;
23
24
  }
package/esm/remoteFile.js CHANGED
@@ -1,27 +1,30 @@
1
1
  function getMessage(e) {
2
- const r = typeof e === 'object' && e !== null && 'message' in e
2
+ const r = typeof e === 'object' &&
3
+ e !== null &&
4
+ 'message' in e &&
5
+ typeof e.message === 'string'
3
6
  ? e.message
4
7
  : `${e}`;
5
8
  return r.replace(/\.$/, '');
6
9
  }
7
10
  export default class RemoteFile {
8
11
  constructor(source, opts = {}) {
9
- this.baseOverrides = {};
10
12
  this.url = source;
11
- const fetch = opts.fetch || globalThis.fetch.bind(globalThis);
12
- if (opts.overrides) {
13
- this.baseOverrides = opts.overrides;
14
- }
15
- this.fetchImplementation = fetch;
13
+ this.baseHeaders = opts.headers ?? {};
14
+ this.baseOverrides = opts.overrides ?? {};
15
+ this.fetchImplementation =
16
+ opts.fetch ??
17
+ ((input, init) => globalThis.fetch(input, init));
16
18
  }
17
19
  async fetch(input, init) {
20
+ const wrapError = (e) => new Error(`${getMessage(e)} fetching ${input}`, { cause: e });
18
21
  let response;
19
22
  try {
20
23
  response = await this.fetchImplementation(input, init);
21
24
  }
22
25
  catch (e) {
23
26
  if (`${e}`.includes('Failed to fetch')) {
24
- // refetch to to help work around a chrome bug (discussed in
27
+ // refetch to help work around a chrome bug (discussed in
25
28
  // generic-filehandle issue #72) in which the chrome cache returns a
26
29
  // CORS error for content in its cache. see also
27
30
  // https://github.com/GMOD/jbrowse-components/pull/1511
@@ -33,11 +36,11 @@ export default class RemoteFile {
33
36
  });
34
37
  }
35
38
  catch (e) {
36
- throw new Error(`${getMessage(e)} fetching ${input}`, { cause: e });
39
+ throw wrapError(e);
37
40
  }
38
41
  }
39
42
  else {
40
- throw new Error(`${getMessage(e)} fetching ${input}`, { cause: e });
43
+ throw wrapError(e);
41
44
  }
42
45
  }
43
46
  return response;
@@ -46,21 +49,15 @@ export default class RemoteFile {
46
49
  if (length === 0) {
47
50
  return new Uint8Array(0);
48
51
  }
49
- const { headers = {}, signal, overrides = {} } = opts;
50
- if (length < Infinity) {
51
- headers.range = `bytes=${position}-${position + length - 1}`;
52
- }
53
- else if (length === Infinity && position !== 0) {
54
- headers.range = `bytes=${position}-`;
52
+ if (Number.isNaN(length) || Number.isNaN(position)) {
53
+ throw new TypeError(`read() called with NaN length or position (length=${length}, position=${position}). The index file may be corrupt.`);
55
54
  }
55
+ const { headers = {}, signal, overrides = {} } = opts;
56
+ headers.range = `bytes=${position}-${position + length - 1}`;
56
57
  const res = await this.fetch(this.url, {
57
58
  ...this.baseOverrides,
58
59
  ...overrides,
59
- headers: {
60
- ...this.baseOverrides.headers,
61
- ...overrides.headers,
62
- ...headers,
63
- },
60
+ headers: { ...this.baseHeaders, ...headers },
64
61
  method: 'GET',
65
62
  redirect: 'follow',
66
63
  mode: 'cors',
@@ -72,7 +69,7 @@ export default class RemoteFile {
72
69
  if ((res.status === 200 && position === 0) || res.status === 206) {
73
70
  // try to parse out the size of the remote file
74
71
  const contentRange = res.headers.get('content-range');
75
- const sizeMatch = /\/(\d+)$/.exec(contentRange || '');
72
+ const sizeMatch = /\/(\d+)$/.exec(contentRange ?? '');
76
73
  if (sizeMatch?.[1]) {
77
74
  this._stat = {
78
75
  size: parseInt(sizeMatch[1], 10),
@@ -91,32 +88,19 @@ export default class RemoteFile {
91
88
  : `HTTP ${res.status} fetching ${this.url}`);
92
89
  }
93
90
  async readFile(options = {}) {
94
- let encoding;
95
- let opts;
96
- if (typeof options === 'string') {
97
- encoding = options;
98
- opts = {};
99
- }
100
- else {
101
- encoding = options.encoding;
102
- const { encoding: _, ...rest } = options;
103
- opts = rest;
104
- }
91
+ const encoding = typeof options === 'string' ? options : options.encoding;
92
+ const opts = typeof options === 'string' ? {} : options;
105
93
  const { headers = {}, signal, overrides = {} } = opts;
106
94
  const res = await this.fetch(this.url, {
107
95
  ...this.baseOverrides,
108
96
  ...overrides,
109
- headers: {
110
- ...this.baseOverrides.headers,
111
- ...overrides.headers,
112
- ...headers,
113
- },
97
+ headers: { ...this.baseHeaders, ...headers },
114
98
  method: 'GET',
115
99
  redirect: 'follow',
116
100
  mode: 'cors',
117
101
  signal,
118
102
  });
119
- if (res.status !== 200) {
103
+ if (!res.ok) {
120
104
  throw new Error(`HTTP ${res.status} fetching ${this.url}`);
121
105
  }
122
106
  if (encoding === 'utf8') {
@@ -140,8 +124,8 @@ export default class RemoteFile {
140
124
  }
141
125
  return this._stat;
142
126
  }
143
- async close() {
144
- return;
127
+ close() {
128
+ return Promise.resolve();
145
129
  }
146
130
  }
147
131
  //# sourceMappingURL=remoteFile.js.map
@@ -1 +1 @@
1
-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CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "generic-filehandle2",
3
3
  "description": "uniform interface for accessing binary data from local files, remote HTTP resources, and browser Blob data",
4
- "version": "2.0.17",
4
+ "version": "2.1.4",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {
@@ -14,7 +14,10 @@
14
14
  "require": "./dist/index.js"
15
15
  }
16
16
  },
17
- "repository": "GMOD/generic-filehandle2",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/GMOD/generic-filehandle2.git"
20
+ },
18
21
  "license": "MIT",
19
22
  "author": {
20
23
  "name": "Colin Diesh",
@@ -32,12 +35,12 @@
32
35
  "scripts": {
33
36
  "test": "vitest",
34
37
  "coverage": "yarn test --coverage",
35
- "lint": "eslint --report-unused-disable-directives --max-warnings 0 src test",
38
+ "lint": "eslint --report-unused-disable-directives --max-warnings 0",
36
39
  "clean": "rimraf dist esm",
37
40
  "format": "prettier --write .",
38
41
  "prebuild": "yarn clean",
39
42
  "build:esm": "tsc --outDir esm",
40
- "build:es5": "tsc --module commonjs --outDir dist",
43
+ "build:es5": "tsc --module commonjs --moduleResolution bundler --outDir dist",
41
44
  "build": "yarn build:esm && yarn build:es5",
42
45
  "postbuild:es5": "echo '{\"type\": \"commonjs\"}' > dist/package.json",
43
46
  "preversion": "yarn lint && yarn test --run && yarn build",
@@ -50,19 +53,20 @@
50
53
  "genomics"
51
54
  ],
52
55
  "devDependencies": {
53
- "@types/node": "^24.3.1",
56
+ "@eslint/js": "^10.0.1",
57
+ "@types/node": "^25.5.0",
54
58
  "@types/range-parser": "^1.2.7",
55
- "@vitest/coverage-v8": "^4.0.15",
56
- "eslint": "^9.16.0",
57
- "eslint-plugin-import": "^2.31.0",
58
- "eslint-plugin-unicorn": "^62.0.0",
59
- "prettier": "^3.4.1",
59
+ "@vitest/coverage-v8": "^4.1.2",
60
+ "eslint": "^9.39.4",
61
+ "eslint-plugin-import": "^2.32.0",
62
+ "eslint-plugin-unicorn": "^64.0.0",
63
+ "prettier": "^3.8.1",
60
64
  "range-parser": "^1.2.1",
61
- "rimraf": "^6.0.0",
65
+ "rimraf": "^6.1.3",
62
66
  "standard-changelog": "^7.0.1",
63
- "typescript": "^5.7.0",
64
- "typescript-eslint": "^8.18.0",
65
- "vitest": "^4.0.15"
67
+ "typescript": "^6.0.2",
68
+ "typescript-eslint": "^8.57.2",
69
+ "vitest": "^4.1.2"
66
70
  },
67
71
  "publishConfig": {
68
72
  "access": "public"
package/src/blobFile.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ BufferEncoding,
2
3
  FilehandleOptions,
3
4
  GenericFilehandle,
4
5
  Stats,
@@ -27,10 +28,7 @@ export default class BlobFile implements GenericFilehandle {
27
28
  return new Uint8Array(0)
28
29
  }
29
30
 
30
- const start = position
31
- const end = start + length
32
-
33
- const slice = this.blob.slice(start, end)
31
+ const slice = this.blob.slice(position, position + length)
34
32
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
35
33
  return slice.bytes
36
34
  ? slice.bytes()
@@ -63,11 +61,11 @@ export default class BlobFile implements GenericFilehandle {
63
61
  }
64
62
  }
65
63
 
66
- public async stat(): Promise<Stats> {
67
- return { size: this.blob.size }
64
+ public stat(): Promise<Stats> {
65
+ return Promise.resolve({ size: this.blob.size })
68
66
  }
69
67
 
70
- public async close(): Promise<void> {
71
- return
68
+ public close(): Promise<void> {
69
+ return Promise.resolve()
72
70
  }
73
71
  }
package/src/filehandle.ts CHANGED
@@ -1,27 +1,33 @@
1
+ // avoids needing to have @types/node as a dependency of the consuming code
2
+ export type BufferEncoding =
3
+ | 'ascii'
4
+ | 'utf8'
5
+ | 'utf-8'
6
+ | 'utf16le'
7
+ | 'utf-16le'
8
+ | 'ucs2'
9
+ | 'ucs-2'
10
+ | 'base64'
11
+ | 'base64url'
12
+ | 'latin1'
13
+ | 'binary'
14
+ | 'hex'
15
+
1
16
  export type Fetcher = (
2
17
  input: RequestInfo,
3
18
  init?: RequestInit,
4
19
  ) => Promise<Response>
5
20
 
6
21
  export interface FilehandleOptions {
7
- /**
8
- * optional AbortSignal object for aborting the request
9
- */
10
22
  signal?: AbortSignal
11
- headers?: any
12
- overrides?: any
23
+ headers?: Record<string, string>
24
+ overrides?: Omit<RequestInit, 'headers'>
13
25
  encoding?: BufferEncoding
14
- /**
15
- * fetch function to use for HTTP requests. defaults to environment's
16
- * global fetch. if there is no global fetch, and a fetch function is not provided,
17
- * throws an error.
18
- */
19
26
  fetch?: Fetcher
20
27
  }
21
28
 
22
29
  export interface Stats {
23
30
  size: number
24
- [key: string]: any
25
31
  }
26
32
 
27
33
  export interface GenericFilehandle {
@@ -44,8 +50,8 @@ export interface GenericFilehandle {
44
50
  readFile<T extends BufferEncoding>(
45
51
  options: Omit<FilehandleOptions, 'encoding'> & { encoding: T },
46
52
  ): T extends BufferEncoding
47
- ? Promise<Uint8Array<ArrayBuffer>>
48
- : Promise<Uint8Array<ArrayBuffer> | string>
53
+ ? Promise<string>
54
+ : Promise<Uint8Array<ArrayBuffer>>
49
55
  stat(): Promise<Stats>
50
56
  close(): Promise<void>
51
57
  }
package/src/index.ts CHANGED
@@ -3,5 +3,3 @@ export * from './filehandle.ts'
3
3
  export { default as BlobFile } from './blobFile.ts'
4
4
  export { default as RemoteFile } from './remoteFile.ts'
5
5
  export { default as LocalFile } from './localFile.ts'
6
-
7
- export { type GenericFilehandle } from './filehandle.ts'
package/src/localFile.ts CHANGED
@@ -1,11 +1,16 @@
1
1
  import { open, readFile, stat } from 'fs/promises'
2
2
 
3
- import type { FilehandleOptions, GenericFilehandle } from './filehandle.ts'
3
+ import type {
4
+ BufferEncoding,
5
+ FilehandleOptions,
6
+ GenericFilehandle,
7
+ Stats,
8
+ } from './filehandle.ts'
4
9
 
5
10
  export default class LocalFile implements GenericFilehandle {
6
11
  private filename: string
7
12
 
8
- public constructor(source: string, _opts: FilehandleOptions = {}) {
13
+ public constructor(source: string) {
9
14
  this.filename = source
10
15
  }
11
16
 
@@ -41,13 +46,18 @@ export default class LocalFile implements GenericFilehandle {
41
46
  public async readFile<T extends BufferEncoding>(
42
47
  options: Omit<FilehandleOptions, 'encoding'> & { encoding: T },
43
48
  ): Promise<string>
49
+ readFile<T extends BufferEncoding>(
50
+ options: Omit<FilehandleOptions, 'encoding'> & { encoding: T },
51
+ ): T extends BufferEncoding
52
+ ? Promise<string>
53
+ : Promise<Uint8Array<ArrayBuffer>>
44
54
  public async readFile(
45
55
  options?: FilehandleOptions | BufferEncoding,
46
56
  ): Promise<Uint8Array<ArrayBuffer> | string> {
47
57
  return readFile(this.filename, options)
48
58
  }
49
59
 
50
- public async stat() {
60
+ public async stat(): Promise<Stats> {
51
61
  return stat(this.filename)
52
62
  }
53
63
 
package/src/remoteFile.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ BufferEncoding,
2
3
  Fetcher,
3
4
  FilehandleOptions,
4
5
  GenericFilehandle,
@@ -7,8 +8,11 @@ import type {
7
8
 
8
9
  function getMessage(e: unknown) {
9
10
  const r =
10
- typeof e === 'object' && e !== null && 'message' in e
11
- ? (e.message as string)
11
+ typeof e === 'object' &&
12
+ e !== null &&
13
+ 'message' in e &&
14
+ typeof e.message === 'string'
15
+ ? e.message
12
16
  : `${e}`
13
17
  return r.replace(/\.$/, '')
14
18
  }
@@ -17,27 +21,32 @@ export default class RemoteFile implements GenericFilehandle {
17
21
  protected url: string
18
22
  private _stat?: Stats
19
23
  private fetchImplementation: Fetcher
20
- private baseOverrides: any = {}
24
+ private baseHeaders: Record<string, string>
25
+ private baseOverrides: Omit<RequestInit, 'headers'>
21
26
 
22
27
  public constructor(source: string, opts: FilehandleOptions = {}) {
23
28
  this.url = source
24
- const fetch = opts.fetch || globalThis.fetch.bind(globalThis)
25
- if (opts.overrides) {
26
- this.baseOverrides = opts.overrides
27
- }
28
- this.fetchImplementation = fetch
29
+ this.baseHeaders = opts.headers ?? {}
30
+ this.baseOverrides = opts.overrides ?? {}
31
+ this.fetchImplementation =
32
+ opts.fetch ??
33
+ ((input: RequestInfo, init?: RequestInit) =>
34
+ globalThis.fetch(input, init))
29
35
  }
30
36
 
31
37
  public async fetch(
32
38
  input: RequestInfo,
33
39
  init: RequestInit | undefined,
34
40
  ): Promise<Response> {
41
+ const wrapError = (e: unknown) =>
42
+ new Error(`${getMessage(e)} fetching ${input}`, { cause: e })
43
+
35
44
  let response
36
45
  try {
37
46
  response = await this.fetchImplementation(input, init)
38
47
  } catch (e) {
39
48
  if (`${e}`.includes('Failed to fetch')) {
40
- // refetch to to help work around a chrome bug (discussed in
49
+ // refetch to help work around a chrome bug (discussed in
41
50
  // generic-filehandle issue #72) in which the chrome cache returns a
42
51
  // CORS error for content in its cache. see also
43
52
  // https://github.com/GMOD/jbrowse-components/pull/1511
@@ -50,10 +59,10 @@ export default class RemoteFile implements GenericFilehandle {
50
59
  cache: 'reload',
51
60
  })
52
61
  } catch (e) {
53
- throw new Error(`${getMessage(e)} fetching ${input}`, { cause: e })
62
+ throw wrapError(e)
54
63
  }
55
64
  } else {
56
- throw new Error(`${getMessage(e)} fetching ${input}`, { cause: e })
65
+ throw wrapError(e)
57
66
  }
58
67
  }
59
68
  return response
@@ -67,20 +76,17 @@ export default class RemoteFile implements GenericFilehandle {
67
76
  if (length === 0) {
68
77
  return new Uint8Array(0)
69
78
  }
70
- const { headers = {}, signal, overrides = {} } = opts
71
- if (length < Infinity) {
72
- headers.range = `bytes=${position}-${position + length - 1}`
73
- } else if (length === Infinity && position !== 0) {
74
- headers.range = `bytes=${position}-`
79
+ if (Number.isNaN(length) || Number.isNaN(position)) {
80
+ throw new TypeError(
81
+ `read() called with NaN length or position (length=${length}, position=${position}). The index file may be corrupt.`,
82
+ )
75
83
  }
84
+ const { headers = {}, signal, overrides = {} } = opts
85
+ headers.range = `bytes=${position}-${position + length - 1}`
76
86
  const res = await this.fetch(this.url, {
77
87
  ...this.baseOverrides,
78
88
  ...overrides,
79
- headers: {
80
- ...this.baseOverrides.headers,
81
- ...overrides.headers,
82
- ...headers,
83
- },
89
+ headers: { ...this.baseHeaders, ...headers },
84
90
  method: 'GET',
85
91
  redirect: 'follow',
86
92
  mode: 'cors',
@@ -94,7 +100,7 @@ export default class RemoteFile implements GenericFilehandle {
94
100
  if ((res.status === 200 && position === 0) || res.status === 206) {
95
101
  // try to parse out the size of the remote file
96
102
  const contentRange = res.headers.get('content-range')
97
- const sizeMatch = /\/(\d+)$/.exec(contentRange || '')
103
+ const sizeMatch = /\/(\d+)$/.exec(contentRange ?? '')
98
104
  if (sizeMatch?.[1]) {
99
105
  this._stat = {
100
106
  size: parseInt(sizeMatch[1], 10),
@@ -130,36 +136,24 @@ export default class RemoteFile implements GenericFilehandle {
130
136
  readFile<T extends BufferEncoding>(
131
137
  options: Omit<FilehandleOptions, 'encoding'> & { encoding: T },
132
138
  ): T extends BufferEncoding
133
- ? Promise<Uint8Array<ArrayBuffer>>
134
- : Promise<Uint8Array<ArrayBuffer> | string>
139
+ ? Promise<string>
140
+ : Promise<Uint8Array<ArrayBuffer>>
135
141
  public async readFile(
136
142
  options: FilehandleOptions | BufferEncoding = {},
137
143
  ): Promise<Uint8Array<ArrayBuffer> | string> {
138
- let encoding
139
- let opts
140
- if (typeof options === 'string') {
141
- encoding = options
142
- opts = {}
143
- } else {
144
- encoding = options.encoding
145
- const { encoding: _, ...rest } = options
146
- opts = rest
147
- }
144
+ const encoding = typeof options === 'string' ? options : options.encoding
145
+ const opts = typeof options === 'string' ? {} : options
148
146
  const { headers = {}, signal, overrides = {} } = opts
149
147
  const res = await this.fetch(this.url, {
150
148
  ...this.baseOverrides,
151
149
  ...overrides,
152
- headers: {
153
- ...this.baseOverrides.headers,
154
- ...overrides.headers,
155
- ...headers,
156
- },
150
+ headers: { ...this.baseHeaders, ...headers },
157
151
  method: 'GET',
158
152
  redirect: 'follow',
159
153
  mode: 'cors',
160
154
  signal,
161
155
  })
162
- if (res.status !== 200) {
156
+ if (!res.ok) {
163
157
  throw new Error(`HTTP ${res.status} fetching ${this.url}`)
164
158
  }
165
159
  if (encoding === 'utf8') {
@@ -183,7 +177,7 @@ export default class RemoteFile implements GenericFilehandle {
183
177
  return this._stat
184
178
  }
185
179
 
186
- public async close(): Promise<void> {
187
- return
180
+ public close(): Promise<void> {
181
+ return Promise.resolve()
188
182
  }
189
183
  }