@octane-xplat/files 0.10.0 → 0.11.1

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.
package/src/types.ts CHANGED
@@ -2,8 +2,71 @@ export interface FileRef {
2
2
  name: string
3
3
  /**
4
4
  * Opaque reference: blob/object URL on web, filesystem path on native.
5
- * `files.writeText()` downloads on web and writes where implemented.
6
- * Picked mobile files may use `content://` URIs.
5
+ * `files.writeText()`/`files.writeBytes()` download on web and write the
6
+ * app sandbox on native. Picked Android files may use `content://` URIs.
7
7
  */
8
8
  uri: string
9
9
  }
10
+
11
+ export interface FilePickOptions {
12
+ startingFolder?: string
13
+ }
14
+
15
+ export interface FileReadBytesOptions {
16
+ /**
17
+ * Reject with a too-large error once the file exceeds this many bytes.
18
+ * Enforced while reading, so oversized sources are never fully loaded.
19
+ */
20
+ maxBytes?: number
21
+ /** Abort an in-progress read. Rejects with an `AbortError`. */
22
+ signal?: AbortSignal
23
+ }
24
+
25
+ export interface FileExportOptions {
26
+ /**
27
+ * MIME type hint for the destination — the Android SAF action type and the
28
+ * web save picker's accept filter. Ignored on iOS.
29
+ */
30
+ mimeType?: string
31
+ }
32
+
33
+ /**
34
+ * `saved`: the platform committed the bytes to the chosen destination —
35
+ * bytes flushed through `ContentResolver` on Android, the export-as-copy
36
+ * picker's destination commit on iOS, or a closed `FileSystemWritableFileStream`
37
+ * on web. `cancelled`: the user dismissed the destination UI. `unavailable`:
38
+ * the platform offers no qualified export surface (browser without the
39
+ * File System Access API, the AppKit leaf).
40
+ */
41
+ export type FileExportResult = 'saved' | 'cancelled' | 'unavailable'
42
+
43
+ /** Shared contract every platform leaf implements. */
44
+ export interface Files {
45
+ /** Opens the platform document picker and returns its first opaque URI. */
46
+ pick(accept?: string, opts?: FilePickOptions): Promise<FileRef | null>
47
+ /** Opens the platform document picker and returns selected opaque URIs. */
48
+ pickMultiple(accept?: string, opts?: FilePickOptions): Promise<FileRef[]>
49
+ readText(ref: FileRef): Promise<string>
50
+ /**
51
+ * Reads the full binary content of a picked or sandbox-written ref.
52
+ * Android `content://` refs are read through `ContentResolver`; iOS picker
53
+ * refs are app-owned import copies; web reads the backing `Blob` directly
54
+ * or fetches foreign URLs.
55
+ */
56
+ readBytes(ref: FileRef, opts?: FileReadBytesOptions): Promise<Uint8Array>
57
+ writeText(name: string, text: string): Promise<FileRef>
58
+ /**
59
+ * Writes bytes inside the app sandbox (native) or starts a browser
60
+ * download (web) and returns a ref suitable for `readBytes`/`release`.
61
+ */
62
+ writeBytes(name: string, bytes: Uint8Array): Promise<FileRef>
63
+ /**
64
+ * User-directed export to a destination the user picks: the Android SAF
65
+ * create action, iOS export-as-copy picker, web `showSaveFilePicker`.
66
+ * Only one export can be in flight — a concurrent call rejects with an
67
+ * `ExportBusyError`.
68
+ */
69
+ export(name: string, bytes: Uint8Array, opts?: FileExportOptions): Promise<FileExportResult>
70
+ /** Free the ref's backing resource (revoke object URLs, delete temp copies). */
71
+ release(ref: FileRef): void
72
+ }
package/types/index.d.ts CHANGED
@@ -12,4 +12,11 @@ export type {
12
12
  } from '../src/props.js'
13
13
 
14
14
  export { files } from '../src/files.js'
15
- export type { FileRef } from '../src/types.js'
15
+ export type {
16
+ FileExportOptions,
17
+ FileExportResult,
18
+ FilePickOptions,
19
+ FileReadBytesOptions,
20
+ FileRef,
21
+ Files,
22
+ } from '../src/types.js'
@@ -11,4 +11,11 @@ export type {
11
11
  } from '../src/props.js'
12
12
 
13
13
  export { files } from '../src/files.macos.js'
14
- export type { FileRef } from '../src/types.js'
14
+ export type {
15
+ FileExportOptions,
16
+ FileExportResult,
17
+ FilePickOptions,
18
+ FileReadBytesOptions,
19
+ FileRef,
20
+ Files,
21
+ } from '../src/types.js'