just-binary 3.0.2 → 3.1.0

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.
@@ -20,6 +20,7 @@ export declare class InMemoryFs implements IFileSystem {
20
20
  mtime?: Date;
21
21
  }): void;
22
22
  readFile(path: string): Promise<ByteStream>;
23
+ readRange(path: string, offset: number, length: number): Promise<Uint8Array>;
23
24
  readFileText(path: string, options?: ReadFileOptions | BufferEncoding): Promise<string>;
24
25
  writeFile(path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): Promise<void>;
25
26
  appendFile(path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): Promise<void>;
@@ -75,6 +75,17 @@ export interface IFileSystem {
75
75
  * @throws if path does not exist or is a directory
76
76
  */
77
77
  readFile(path: string): Promise<ByteStream>;
78
+ /**
79
+ * Read a byte range from a file. Returns at most `length` bytes starting at
80
+ * `offset`; if the range extends past EOF, returns the truncated tail (may
81
+ * be empty). Designed for random-access workloads (ZIP central directory,
82
+ * PDF xref, file footers) that would otherwise have to drain the whole
83
+ * stream into memory.
84
+ *
85
+ * @throws if path does not exist or is a directory, or if offset/length
86
+ * are negative or non-finite
87
+ */
88
+ readRange(path: string, offset: number, length: number): Promise<Uint8Array>;
78
89
  /**
79
90
  * Read a file fully as decoded text (default encoding: utf8).
80
91
  * Convenience for small/text files.
@@ -85,6 +85,7 @@ export declare class MountableFs implements IFileSystem {
85
85
  */
86
86
  private getChildMountPoints;
87
87
  readFile(path: string): Promise<ByteStream>;
88
+ readRange(path: string, offset: number, length: number): Promise<Uint8Array>;
88
89
  readFileText(path: string, options?: ReadFileOptions | BufferEncoding): Promise<string>;
89
90
  writeFile(path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): Promise<void>;
90
91
  appendFile(path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): Promise<void>;
@@ -80,6 +80,13 @@ export declare class OverlayFs implements IFileSystem {
80
80
  */
81
81
  private existsInOverlay;
82
82
  readFile(path: string): Promise<ByteStream>;
83
+ readRange(path: string, offset: number, length: number): Promise<Uint8Array>;
84
+ /**
85
+ * Resolve a path through symlinks for read purposes, returning either the
86
+ * in-memory chunked representation or the underlying real-fs path so the
87
+ * caller can choose between random-access and full reads.
88
+ */
89
+ private resolveForRead;
83
90
  readFileText(path: string, options?: ReadFileOptions | BufferEncoding): Promise<string>;
84
91
  /**
85
92
  * Internal: resolve symlinks and produce raw chunks. Memory hits return
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shared helpers for readRange implementations across filesystem backends.
3
+ */
4
+ export declare function validateRange(offset: number, length: number): void;
5
+ /**
6
+ * Slice a contiguous byte range out of a chunked file representation. Walks
7
+ * chunks lazily; only the requested bytes are copied into the output. If the
8
+ * requested range extends past `totalSize`, the result is truncated.
9
+ */
10
+ export declare function sliceChunks(chunks: Uint8Array[], totalSize: number, offset: number, length: number): Uint8Array;
@@ -35,6 +35,7 @@ export declare class ReadWriteFs implements IFileSystem {
35
35
  */
36
36
  private normalizePath;
37
37
  readFile(path: string): Promise<ByteStream>;
38
+ readRange(path: string, offset: number, length: number): Promise<Uint8Array>;
38
39
  readFileText(path: string, options?: ReadFileOptions | BufferEncoding): Promise<string>;
39
40
  writeFile(path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): Promise<void>;
40
41
  appendFile(path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-binary",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
4
4
  "description": "A simulated bash environment with virtual filesystem",
5
5
  "repository": {
6
6
  "type": "git",