@peerbit/please-lib 2.0.1 → 2.0.2

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.
@@ -3,22 +3,35 @@ import { Documents } from "@peerbit/document";
3
3
  import { PublicSignKey } from "@peerbit/crypto";
4
4
  import { TrustedNetwork } from "@peerbit/trusted-network";
5
5
  import { ReplicationOptions } from "@peerbit/shared-log";
6
+ type FileReadOptions = {
7
+ timeout?: number;
8
+ progress?: (progress: number) => any;
9
+ };
10
+ export interface ReReadableChunkSource {
11
+ size: bigint;
12
+ readChunks(chunkSize: number): AsyncIterable<Uint8Array>;
13
+ }
14
+ interface ChunkWritable {
15
+ write(chunk: Uint8Array): Promise<void> | void;
16
+ close?(): Promise<void> | void;
17
+ abort?(reason?: unknown): Promise<void> | void;
18
+ }
6
19
  export declare abstract class AbstractFile {
7
20
  abstract id: string;
8
21
  abstract name: string;
9
- abstract size: number;
22
+ abstract size: bigint;
10
23
  abstract parentId?: string;
11
- abstract getFile<OutputType extends "chunks" | "joined" = "joined", Output = OutputType extends "chunks" ? Uint8Array[] : Uint8Array>(files: Files, properties?: {
24
+ abstract streamFile(files: Files, properties?: FileReadOptions): AsyncIterable<Uint8Array>;
25
+ getFile<OutputType extends "chunks" | "joined" = "joined", Output = OutputType extends "chunks" ? Uint8Array[] : Uint8Array>(files: Files, properties?: {
12
26
  as: OutputType;
13
- timeout?: number;
14
- progress?: (progress: number) => any;
15
- }): Promise<Output>;
27
+ } & FileReadOptions): Promise<Output>;
28
+ writeFile(files: Files, writable: ChunkWritable, properties?: FileReadOptions): Promise<void>;
16
29
  abstract delete(files: Files): Promise<void>;
17
30
  }
18
31
  export declare class IndexableFile {
19
32
  id: string;
20
33
  name: string;
21
- size: number;
34
+ size: bigint;
22
35
  parentId?: string;
23
36
  constructor(file: AbstractFile);
24
37
  }
@@ -26,40 +39,43 @@ export declare class TinyFile extends AbstractFile {
26
39
  id: string;
27
40
  name: string;
28
41
  file: Uint8Array;
42
+ hash: string;
29
43
  parentId?: string;
30
- get size(): number;
44
+ index?: number;
45
+ get size(): bigint;
31
46
  constructor(properties: {
32
47
  id?: string;
33
48
  name: string;
34
49
  file: Uint8Array;
50
+ hash?: string;
35
51
  parentId?: string;
52
+ index?: number;
36
53
  });
37
- getFile<OutputType extends "chunks" | "joined" = "joined", Output = OutputType extends "chunks" ? Uint8Array[] : Uint8Array>(_files: Files, properties?: {
38
- as: OutputType;
39
- progress?: (progress: number) => any;
40
- }): Promise<Output>;
54
+ streamFile(_files: Files, properties?: FileReadOptions): AsyncIterable<Uint8Array>;
41
55
  delete(): Promise<void>;
42
56
  }
43
57
  export declare class LargeFile extends AbstractFile {
44
58
  id: string;
45
59
  name: string;
46
- fileIds: string[];
47
- size: number;
60
+ size: bigint;
61
+ chunkCount: number;
62
+ ready: boolean;
63
+ finalHash?: string;
48
64
  constructor(properties: {
49
- id: string;
65
+ id?: string;
50
66
  name: string;
51
- fileIds: string[];
52
- size: number;
67
+ size: bigint;
68
+ chunkCount: number;
69
+ ready?: boolean;
70
+ finalHash?: string;
53
71
  });
54
- static create(name: string, file: Uint8Array, files: Files, progress?: (progress: number) => void): Promise<LargeFile>;
55
72
  get parentId(): undefined;
56
- fetchChunks(files: Files): Promise<import("@peerbit/document").WithIndexedContext<AbstractFile, IndexableFile>[]>;
57
- delete(files: Files): Promise<void>;
58
- getFile<OutputType extends "chunks" | "joined" = "joined", Output = OutputType extends "chunks" ? Uint8Array[] : Uint8Array>(files: Files, properties?: {
59
- as: OutputType;
73
+ fetchChunks(files: Files, properties?: {
60
74
  timeout?: number;
61
- progress?: (progress: number) => any;
62
- }): Promise<Output>;
75
+ }): Promise<TinyFile[]>;
76
+ delete(files: Files): Promise<void>;
77
+ private resolveChunk;
78
+ streamFile(files: Files, properties?: FileReadOptions): AsyncIterable<Uint8Array>;
63
79
  }
64
80
  type Args = {
65
81
  replicate: ReplicationOptions;
@@ -69,16 +85,29 @@ export declare class Files extends Program<Args> {
69
85
  name: string;
70
86
  trustGraph?: TrustedNetwork;
71
87
  files: Documents<AbstractFile, IndexableFile>;
88
+ persistChunkReads: boolean;
72
89
  constructor(properties?: {
73
90
  id?: Uint8Array;
74
91
  name?: string;
75
92
  rootKey?: PublicSignKey;
76
93
  });
77
- add(name: string, file: Uint8Array, parentId?: string, progress?: (progress: number) => void): Promise<string>;
94
+ add(name: string, file: Uint8Array | Blob, parentId?: string, progress?: (progress: number) => void): Promise<string>;
95
+ addBlob(name: string, file: Blob, parentId?: string, progress?: (progress: number) => void): Promise<string>;
96
+ addSource(name: string, source: ReReadableChunkSource, parentId?: string, progress?: (progress: number) => void): Promise<string>;
97
+ private cleanupChunkedUpload;
98
+ private addChunkedFile;
78
99
  removeById(id: string): Promise<void>;
79
100
  removeByName(name: string): Promise<void>;
80
101
  list(): Promise<import("@peerbit/document").WithIndexedContext<AbstractFile, IndexableFile>[]>;
81
102
  countLocalChunks(parent: LargeFile): Promise<number>;
103
+ resolveById(id: string, properties?: {
104
+ timeout?: number;
105
+ replicate?: boolean;
106
+ }): Promise<AbstractFile | undefined>;
107
+ resolveByName(name: string, properties?: {
108
+ timeout?: number;
109
+ replicate?: boolean;
110
+ }): Promise<AbstractFile | undefined>;
82
111
  /**
83
112
  * Get by name
84
113
  * @param id