core-3nweb-client-lib 0.48.1 → 0.48.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.
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { BufferEncodingOption,
|
|
1
|
+
import type { BufferEncodingOption, Mode, ObjectEncodingOptions, OpenMode, RmDirOptions, StatOptions, Stats } from 'fs';
|
|
2
2
|
export type { Stats } from 'fs';
|
|
3
3
|
export type { FileException } from '../lib-common/exceptions/file';
|
|
4
|
-
export type FileHandle = fsFns.FileHandle;
|
|
5
4
|
/**
|
|
6
5
|
* This should be injected at globalThis.platform.device_fs
|
|
7
6
|
*/
|
|
@@ -59,3 +58,16 @@ declare function rmdir(path: string, options?: RmDirOptions): Promise<void>;
|
|
|
59
58
|
declare function unlink(path: string): Promise<void>;
|
|
60
59
|
declare function rename(oldPath: string, newPath: string): Promise<void>;
|
|
61
60
|
declare function truncate(path: string, len?: number): Promise<void>;
|
|
61
|
+
export interface FileHandle {
|
|
62
|
+
readonly fd: number;
|
|
63
|
+
stat(): Promise<Stats>;
|
|
64
|
+
close(): Promise<void>;
|
|
65
|
+
read(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<{
|
|
66
|
+
bytesRead: number;
|
|
67
|
+
}>;
|
|
68
|
+
write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<{
|
|
69
|
+
bytesWritten: number;
|
|
70
|
+
}>;
|
|
71
|
+
sync(): Promise<void>;
|
|
72
|
+
truncate(len?: number): Promise<void>;
|
|
73
|
+
}
|
|
@@ -80,12 +80,6 @@ export declare function getFolderContentSize(folderPath: string): Promise<number
|
|
|
80
80
|
* @returns a promise, resolvable when all bytes were written to it.
|
|
81
81
|
*/
|
|
82
82
|
export declare function write(fh: FileHandle, pos: number, buf: Buffer): Promise<void>;
|
|
83
|
-
/**
|
|
84
|
-
* @param fh is an open file handle in append mode.
|
|
85
|
-
* @param buf is a buffer, from which all bytes should be written into the file.
|
|
86
|
-
* @returns a promise, resolvable when all bytes were written to it.
|
|
87
|
-
*/
|
|
88
|
-
export declare function append(fh: FileHandle, buf: Buffer): Promise<void>;
|
|
89
83
|
/**
|
|
90
84
|
* @param filePath
|
|
91
85
|
* @param pos is a position in the file, from which writting should start
|
|
@@ -26,7 +26,6 @@ exports.existsFolder = existsFolder;
|
|
|
26
26
|
exports.getFileSize = getFileSize;
|
|
27
27
|
exports.getFolderContentSize = getFolderContentSize;
|
|
28
28
|
exports.write = write;
|
|
29
|
-
exports.append = append;
|
|
30
29
|
exports.streamToExistingFile = streamToExistingFile;
|
|
31
30
|
exports.read = read;
|
|
32
31
|
exports.rmDirWithContent = rmDirWithContent;
|
|
@@ -191,18 +190,6 @@ async function write(fh, pos, buf) {
|
|
|
191
190
|
}
|
|
192
191
|
await fh.sync();
|
|
193
192
|
}
|
|
194
|
-
/**
|
|
195
|
-
* @param fh is an open file handle in append mode.
|
|
196
|
-
* @param buf is a buffer, from which all bytes should be written into the file.
|
|
197
|
-
* @returns a promise, resolvable when all bytes were written to it.
|
|
198
|
-
*/
|
|
199
|
-
async function append(fh, buf) {
|
|
200
|
-
let bytesWritten = 0;
|
|
201
|
-
while (bytesWritten < buf.length) {
|
|
202
|
-
const { bytesWritten: bNum } = await fh.write(buf, bytesWritten, buf.length - bytesWritten);
|
|
203
|
-
bytesWritten += bNum;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
193
|
/**
|
|
207
194
|
* @param filePath is a path to an existing file
|
|
208
195
|
* @param pos is a position in the file, from which writing should start
|
|
@@ -86,6 +86,7 @@ class ObjVersionFile {
|
|
|
86
86
|
await fs.writeFromBuf(fh, ofs, layoutBytes);
|
|
87
87
|
await recordLayoutOffsetInV1(fh, ofs);
|
|
88
88
|
await fh.truncate(ofs + layoutBytes.length);
|
|
89
|
+
await fh.sync();
|
|
89
90
|
}
|
|
90
91
|
withRWFile(action) {
|
|
91
92
|
return this.writeProc.startOrChain(async () => {
|
|
@@ -188,7 +189,7 @@ class ObjVersionFile {
|
|
|
188
189
|
}
|
|
189
190
|
await this.withROFile(async (fd) => {
|
|
190
191
|
const src = (0, fs_1.createReadStream)('', {
|
|
191
|
-
fd,
|
|
192
|
+
fd: fd,
|
|
192
193
|
autoClose: false,
|
|
193
194
|
start: chunkInfo.fileOfs,
|
|
194
195
|
end: chunkInfo.fileOfs + chunkInfo.len - 1
|
|
@@ -221,7 +222,7 @@ class ObjVersionFile {
|
|
|
221
222
|
if ((chunk.type === 'new-on-disk')
|
|
222
223
|
|| (chunk.type === 'base-on-disk')) {
|
|
223
224
|
const src = (0, fs_1.createReadStream)('', {
|
|
224
|
-
fd,
|
|
225
|
+
fd: fd,
|
|
225
226
|
autoClose: false,
|
|
226
227
|
start: chunk.fileOfs,
|
|
227
228
|
end: chunk.fileOfs + chunk.len - 1
|