@filen/sync 0.1.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/.eslintrc +16 -0
- package/.gitattributes +2 -0
- package/.node-version +1 -0
- package/.prettierrc +14 -0
- package/LICENSE +661 -0
- package/README.md +1 -0
- package/SECURITY.md +17 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/deltas.d.ts +106 -0
- package/dist/lib/deltas.js +217 -0
- package/dist/lib/deltas.js.map +1 -0
- package/dist/lib/filesystems/local.d.ts +160 -0
- package/dist/lib/filesystems/local.js +273 -0
- package/dist/lib/filesystems/local.js.map +1 -0
- package/dist/lib/filesystems/remote.d.ts +102 -0
- package/dist/lib/filesystems/remote.js +344 -0
- package/dist/lib/filesystems/remote.js.map +1 -0
- package/dist/lib/state.d.ts +43 -0
- package/dist/lib/state.js +228 -0
- package/dist/lib/state.js.map +1 -0
- package/dist/lib/sync.d.ts +46 -0
- package/dist/lib/sync.js +99 -0
- package/dist/lib/sync.js.map +1 -0
- package/dist/lib/tasks.d.ts +116 -0
- package/dist/lib/tasks.js +111 -0
- package/dist/lib/tasks.js.map +1 -0
- package/dist/semaphore.d.ts +14 -0
- package/dist/semaphore.js +64 -0
- package/dist/semaphore.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +24 -0
- package/dist/utils.js +53 -0
- package/dist/utils.js.map +1 -0
- package/index.d.ts +298 -0
- package/package.json +58 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LocalFileSystem = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const watcher_1 = __importDefault(require("@parcel/watcher"));
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const process_1 = __importDefault(require("process"));
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
13
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
14
|
+
const stream_1 = require("stream");
|
|
15
|
+
const util_1 = require("util");
|
|
16
|
+
const pipelineAsync = (0, util_1.promisify)(stream_1.pipeline);
|
|
17
|
+
/**
|
|
18
|
+
* LocalFileSystem
|
|
19
|
+
* @date 3/2/2024 - 12:38:22 PM
|
|
20
|
+
*
|
|
21
|
+
* @export
|
|
22
|
+
* @class LocalFileSystem
|
|
23
|
+
* @typedef {LocalFileSystem}
|
|
24
|
+
*/
|
|
25
|
+
class LocalFileSystem {
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of LocalFileSystem.
|
|
28
|
+
* @date 3/2/2024 - 12:38:20 PM
|
|
29
|
+
*
|
|
30
|
+
* @constructor
|
|
31
|
+
* @public
|
|
32
|
+
* @param {{ sync: Sync }} param0
|
|
33
|
+
* @param {Sync} param0.sync
|
|
34
|
+
*/
|
|
35
|
+
constructor({ sync }) {
|
|
36
|
+
this.lastDirectoryChangeTimestamp = Date.now() - constants_1.SYNC_INTERVAL * 2;
|
|
37
|
+
this.getDirectoryTreeCache = {
|
|
38
|
+
timestamp: 0,
|
|
39
|
+
tree: {},
|
|
40
|
+
inodes: {}
|
|
41
|
+
};
|
|
42
|
+
this.watcherRunning = false;
|
|
43
|
+
this.watcherInstance = null;
|
|
44
|
+
this.sync = sync;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the local directory tree.
|
|
48
|
+
* @date 3/2/2024 - 12:38:13 PM
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
* @async
|
|
52
|
+
* @returns {Promise<LocalTree>}
|
|
53
|
+
*/
|
|
54
|
+
async getDirectoryTree() {
|
|
55
|
+
if (this.lastDirectoryChangeTimestamp > 0 &&
|
|
56
|
+
this.getDirectoryTreeCache.timestamp > 0 &&
|
|
57
|
+
this.lastDirectoryChangeTimestamp < this.getDirectoryTreeCache.timestamp) {
|
|
58
|
+
return {
|
|
59
|
+
tree: this.getDirectoryTreeCache.tree,
|
|
60
|
+
inodes: this.getDirectoryTreeCache.inodes
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const tree = {};
|
|
64
|
+
const inodes = {};
|
|
65
|
+
const dir = await fs_extra_1.default.readdir(this.sync.syncPair.localPath, {
|
|
66
|
+
recursive: true,
|
|
67
|
+
encoding: "utf-8"
|
|
68
|
+
});
|
|
69
|
+
const promises = [];
|
|
70
|
+
for (const entry of dir) {
|
|
71
|
+
promises.push(new Promise((resolve, reject) => {
|
|
72
|
+
if (entry.startsWith(".filen.trash.local")) {
|
|
73
|
+
resolve();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const itemPath = path_1.default.join(this.sync.syncPair.localPath, entry);
|
|
77
|
+
const entryPath = `/${process_1.default.platform === "win32" ? entry.replace(/\\/g, "/") : entry}`;
|
|
78
|
+
fs_extra_1.default.stat(itemPath)
|
|
79
|
+
.then(stats => {
|
|
80
|
+
const item = {
|
|
81
|
+
lastModified: parseInt(stats.mtimeMs), // Sometimes comes as a float, but we need an int
|
|
82
|
+
type: stats.isDirectory() ? "directory" : "file",
|
|
83
|
+
path: entryPath,
|
|
84
|
+
creation: parseInt(stats.birthtimeMs), // Sometimes comes as a float, but we need an int
|
|
85
|
+
size: stats.size,
|
|
86
|
+
inode: stats.ino
|
|
87
|
+
};
|
|
88
|
+
tree[entryPath] = item;
|
|
89
|
+
inodes[stats.ino] = item;
|
|
90
|
+
resolve();
|
|
91
|
+
})
|
|
92
|
+
.catch(reject);
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
await (0, utils_1.promiseAllChunked)(promises);
|
|
96
|
+
this.getDirectoryTreeCache = {
|
|
97
|
+
timestamp: Date.now(),
|
|
98
|
+
tree,
|
|
99
|
+
inodes
|
|
100
|
+
};
|
|
101
|
+
return { tree, inodes };
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Start the local sync directory watcher.
|
|
105
|
+
* @date 3/2/2024 - 12:38:00 PM
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
* @async
|
|
109
|
+
* @returns {Promise<void>}
|
|
110
|
+
*/
|
|
111
|
+
async startDirectoryWatcher() {
|
|
112
|
+
if (this.watcherInstance) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.watcherInstance = await watcher_1.default.subscribe(this.sync.syncPair.localPath, (err, events) => {
|
|
116
|
+
if (!err && events) {
|
|
117
|
+
this.lastDirectoryChangeTimestamp = Date.now();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Stop the local sync directory watcher.
|
|
123
|
+
* @date 3/2/2024 - 12:37:48 PM
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
* @async
|
|
127
|
+
* @returns {Promise<void>}
|
|
128
|
+
*/
|
|
129
|
+
async stopDirectoryWatcher() {
|
|
130
|
+
if (!this.watcherInstance) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
await this.watcherInstance.unsubscribe();
|
|
134
|
+
this.watcherInstance = null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Wait for local directory updates to be done.
|
|
138
|
+
* Sometimes the user might copy a lot of new files, folders etc.
|
|
139
|
+
* We want to wait (or at least try) until all local operations are done until we start syncing.
|
|
140
|
+
* This can save a lot of sync cycles.
|
|
141
|
+
* @date 3/1/2024 - 10:40:14 PM
|
|
142
|
+
*
|
|
143
|
+
* @public
|
|
144
|
+
* @async
|
|
145
|
+
* @returns {Promise<void>}
|
|
146
|
+
*/
|
|
147
|
+
async waitForLocalDirectoryChanges() {
|
|
148
|
+
await new Promise(resolve => {
|
|
149
|
+
if (Date.now() > this.lastDirectoryChangeTimestamp + constants_1.SYNC_INTERVAL) {
|
|
150
|
+
resolve();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const wait = setInterval(() => {
|
|
154
|
+
if (Date.now() > this.lastDirectoryChangeTimestamp + constants_1.SYNC_INTERVAL) {
|
|
155
|
+
clearInterval(wait);
|
|
156
|
+
resolve();
|
|
157
|
+
}
|
|
158
|
+
}, 100);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Creates a hash of a file using streams.
|
|
163
|
+
* @date 3/2/2024 - 9:29:48 AM
|
|
164
|
+
*
|
|
165
|
+
* @public
|
|
166
|
+
* @async
|
|
167
|
+
* @param {{ relativePath: string; algorithm: "sha512" }} param0
|
|
168
|
+
* @param {string} param0.relativePath
|
|
169
|
+
* @param {"sha512"} param0.algorithm
|
|
170
|
+
* @returns {Promise<string>}
|
|
171
|
+
*/
|
|
172
|
+
async createFileHash({ relativePath, algorithm }) {
|
|
173
|
+
const localPath = path_1.default.join(this.sync.syncPair.localPath, relativePath);
|
|
174
|
+
const hasher = crypto_1.default.createHash(algorithm);
|
|
175
|
+
await pipelineAsync(fs_extra_1.default.createReadStream(localPath), hasher);
|
|
176
|
+
const hash = hasher.digest("hex");
|
|
177
|
+
return hash;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Create a directory inside the local sync path. Recursively creates intermediate directories if needed.
|
|
181
|
+
* @date 3/2/2024 - 12:36:23 PM
|
|
182
|
+
*
|
|
183
|
+
* @public
|
|
184
|
+
* @async
|
|
185
|
+
* @param {{ relativePath: string }} param0
|
|
186
|
+
* @param {string} param0.relativePath
|
|
187
|
+
* @returns {Promise<fs.Stats>}
|
|
188
|
+
*/
|
|
189
|
+
async mkdir({ relativePath }) {
|
|
190
|
+
const localPath = path_1.default.join(this.sync.syncPair.localPath, relativePath);
|
|
191
|
+
await fs_extra_1.default.ensureDir(localPath);
|
|
192
|
+
return await fs_extra_1.default.stat(localPath);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Delete a file/directory inside the local sync path.
|
|
196
|
+
* @date 3/3/2024 - 10:05:55 PM
|
|
197
|
+
*
|
|
198
|
+
* @public
|
|
199
|
+
* @async
|
|
200
|
+
* @param {{ relativePath: string; permanent?: boolean }} param0
|
|
201
|
+
* @param {string} param0.relativePath
|
|
202
|
+
* @param {boolean} [param0.permanent=false]
|
|
203
|
+
* @returns {Promise<void>}
|
|
204
|
+
*/
|
|
205
|
+
async unlink({ relativePath, permanent = false }) {
|
|
206
|
+
const localPath = path_1.default.join(this.sync.syncPair.localPath, relativePath);
|
|
207
|
+
if (!permanent) {
|
|
208
|
+
const localTrashPath = path_1.default.join(this.sync.syncPair.localPath, ".filen.trash.local");
|
|
209
|
+
await fs_extra_1.default.ensureDir(localTrashPath);
|
|
210
|
+
await fs_extra_1.default.move(localPath, path_1.default.join(localTrashPath, path_1.default.posix.basename(relativePath)), {
|
|
211
|
+
overwrite: true
|
|
212
|
+
});
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
await fs_extra_1.default.rm(localPath, {
|
|
216
|
+
force: true,
|
|
217
|
+
maxRetries: 60 * 10,
|
|
218
|
+
recursive: true,
|
|
219
|
+
retryDelay: 100
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Rename a file/directory inside the local sync path. Recursively creates intermediate directories if needed.
|
|
224
|
+
* @date 3/2/2024 - 12:41:15 PM
|
|
225
|
+
*
|
|
226
|
+
* @public
|
|
227
|
+
* @async
|
|
228
|
+
* @param {{ fromRelativePath: string; toRelativePath: string }} param0
|
|
229
|
+
* @param {string} param0.fromRelativePath
|
|
230
|
+
* @param {string} param0.toRelativePath
|
|
231
|
+
* @returns {Promise<fs.Stats>}
|
|
232
|
+
*/
|
|
233
|
+
async rename({ fromRelativePath, toRelativePath }) {
|
|
234
|
+
const fromLocalPath = path_1.default.join(this.sync.syncPair.localPath, fromRelativePath);
|
|
235
|
+
const toLocalPath = path_1.default.join(this.sync.syncPair.localPath, toRelativePath);
|
|
236
|
+
const fromLocalPathParentPath = path_1.default.dirname(fromLocalPath);
|
|
237
|
+
const toLocalPathParentPath = path_1.default.dirname(toLocalPath);
|
|
238
|
+
await fs_extra_1.default.ensureDir(toLocalPathParentPath);
|
|
239
|
+
if (fromLocalPathParentPath === toLocalPathParentPath) {
|
|
240
|
+
await fs_extra_1.default.rename(fromLocalPath, toLocalPath);
|
|
241
|
+
return await fs_extra_1.default.stat(toLocalPath);
|
|
242
|
+
}
|
|
243
|
+
await fs_extra_1.default.move(fromLocalPath, toLocalPath, {
|
|
244
|
+
overwrite: true
|
|
245
|
+
});
|
|
246
|
+
return await fs_extra_1.default.stat(toLocalPath);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Upload a local file.
|
|
250
|
+
* @date 3/2/2024 - 9:43:58 PM
|
|
251
|
+
*
|
|
252
|
+
* @public
|
|
253
|
+
* @async
|
|
254
|
+
* @param {{ relativePath: string }} param0
|
|
255
|
+
* @param {string} param0.relativePath
|
|
256
|
+
* @returns {Promise<void>}
|
|
257
|
+
*/
|
|
258
|
+
async upload({ relativePath }) {
|
|
259
|
+
const localPath = path_1.default.join(this.sync.syncPair.localPath, relativePath);
|
|
260
|
+
const parentPath = path_1.default.posix.dirname(relativePath);
|
|
261
|
+
await this.sync.remoteFileSystem.mkdir({ relativePath: parentPath });
|
|
262
|
+
const parentUUID = await this.sync.remoteFileSystem.pathToItemUUID({ relativePath: parentPath });
|
|
263
|
+
if (!parentUUID) {
|
|
264
|
+
throw new Error(`Could not upload ${relativePath}: Parent path not found.`);
|
|
265
|
+
}
|
|
266
|
+
const hash = await this.createFileHash({ relativePath, algorithm: "sha512" });
|
|
267
|
+
this.sync.localFileHashes[relativePath] = hash;
|
|
268
|
+
return await this.sync.sdk.cloud().uploadLocalFile({ source: localPath, parent: parentUUID });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.LocalFileSystem = LocalFileSystem;
|
|
272
|
+
exports.default = LocalFileSystem;
|
|
273
|
+
//# sourceMappingURL=local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../../src/lib/filesystems/local.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAyB;AACzB,8DAAqC;AACrC,uCAA+C;AAC/C,gDAA6B;AAC7B,sDAA6B;AAE7B,+CAA+C;AAC/C,oDAA2B;AAC3B,mCAAiC;AACjC,+BAAgC;AAGhC,MAAM,aAAa,GAAG,IAAA,gBAAS,EAAC,iBAAQ,CAAC,CAAA;AAezC;;;;;;;GAOG;AACH,MAAa,eAAe;IAW3B;;;;;;;;OAQG;IACH,YAAmB,EAAE,IAAI,EAAkB;QAlBpC,iCAA4B,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,yBAAa,GAAG,CAAC,CAAA;QAC7D,0BAAqB,GAAkF;YAC7G,SAAS,EAAE,CAAC;YACZ,IAAI,EAAE,EAAE;YACR,MAAM,EAAE,EAAE;SACV,CAAA;QACM,mBAAc,GAAG,KAAK,CAAA;QACrB,oBAAe,GAAqC,IAAI,CAAA;QAY/D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,gBAAgB;QAC5B,IACC,IAAI,CAAC,4BAA4B,GAAG,CAAC;YACrC,IAAI,CAAC,qBAAqB,CAAC,SAAS,GAAG,CAAC;YACxC,IAAI,CAAC,4BAA4B,GAAG,IAAI,CAAC,qBAAqB,CAAC,SAAS,EACvE,CAAC;YACF,OAAO;gBACN,IAAI,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI;gBACrC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC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AA;QAE9C,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IAC9F,CAAC;CACD;AAzSD,0CAySC;AAED,kBAAe,eAAe,CAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type Sync from "../sync";
|
|
3
|
+
import type { CloudItemTree, FSItemType } from "@filen/sdk";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import type { DistributiveOmit, Prettify } from "../../types";
|
|
6
|
+
export type RemoteItem = Prettify<DistributiveOmit<CloudItemTree, "parent"> & {
|
|
7
|
+
path: string;
|
|
8
|
+
}>;
|
|
9
|
+
export type RemoteDirectoryTree = Record<string, RemoteItem>;
|
|
10
|
+
export type RemoteDirectoryUUIDs = Record<string, RemoteItem>;
|
|
11
|
+
export type RemoteTree = {
|
|
12
|
+
tree: RemoteDirectoryTree;
|
|
13
|
+
uuids: RemoteDirectoryUUIDs;
|
|
14
|
+
};
|
|
15
|
+
export declare class RemoteFileSystem {
|
|
16
|
+
private readonly sync;
|
|
17
|
+
getDirectoryTreeCache: {
|
|
18
|
+
timestamp: number;
|
|
19
|
+
tree: RemoteDirectoryTree;
|
|
20
|
+
uuids: RemoteDirectoryUUIDs;
|
|
21
|
+
};
|
|
22
|
+
private readonly mutex;
|
|
23
|
+
private readonly mkdirMutex;
|
|
24
|
+
constructor({ sync }: {
|
|
25
|
+
sync: Sync;
|
|
26
|
+
});
|
|
27
|
+
getDirectoryTree(): Promise<RemoteTree>;
|
|
28
|
+
/**
|
|
29
|
+
* Find the corresponding UUID of the relative path.
|
|
30
|
+
* @date 3/3/2024 - 6:55:53 PM
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
* @async
|
|
34
|
+
* @param {{ relativePath: string; type?: FSItemType }} param0
|
|
35
|
+
* @param {string} param0.relativePath
|
|
36
|
+
* @param {FSItemType} param0.type
|
|
37
|
+
* @returns {Promise<string | null>}
|
|
38
|
+
*/
|
|
39
|
+
pathToItemUUID({ relativePath, type }: {
|
|
40
|
+
relativePath: string;
|
|
41
|
+
type?: FSItemType;
|
|
42
|
+
}): Promise<string | null>;
|
|
43
|
+
/**
|
|
44
|
+
* Create a directory inside the remote sync path. Recursively creates intermediate directories if needed.
|
|
45
|
+
* @date 3/2/2024 - 9:34:14 PM
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
* @async
|
|
49
|
+
* @param {{ relativePath: string }} param0
|
|
50
|
+
* @param {string} param0.relativePath
|
|
51
|
+
* @returns {Promise<string>}
|
|
52
|
+
*/
|
|
53
|
+
mkdir({ relativePath }: {
|
|
54
|
+
relativePath: string;
|
|
55
|
+
}): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Delete a file/directory inside the remote sync path.
|
|
58
|
+
* @date 3/3/2024 - 7:03:18 PM
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
* @async
|
|
62
|
+
* @param {{ relativePath: string; type?: FSItemType; permanent?: boolean }} param0
|
|
63
|
+
* @param {string} param0.relativePath
|
|
64
|
+
* @param {FSItemType} param0.type
|
|
65
|
+
* @param {boolean} [param0.permanent=false]
|
|
66
|
+
* @returns {Promise<void>}
|
|
67
|
+
*/
|
|
68
|
+
unlink({ relativePath, type, permanent }: {
|
|
69
|
+
relativePath: string;
|
|
70
|
+
type?: FSItemType;
|
|
71
|
+
permanent?: boolean;
|
|
72
|
+
}): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Rename a file/directory inside the remote sync path. Recursively creates intermediate directories if needed.
|
|
75
|
+
* @date 3/2/2024 - 9:35:12 PM
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
* @async
|
|
79
|
+
* @param {{ fromRelativePath: string; toRelativePath: string }} param0
|
|
80
|
+
* @param {string} param0.fromRelativePath
|
|
81
|
+
* @param {string} param0.toRelativePath
|
|
82
|
+
* @returns {Promise<void>}
|
|
83
|
+
*/
|
|
84
|
+
rename({ fromRelativePath, toRelativePath }: {
|
|
85
|
+
fromRelativePath: string;
|
|
86
|
+
toRelativePath: string;
|
|
87
|
+
}): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Download a remote file.
|
|
90
|
+
* @date 3/2/2024 - 9:41:59 PM
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
* @async
|
|
94
|
+
* @param {{ relativePath: string }} param0
|
|
95
|
+
* @param {string} param0.relativePath
|
|
96
|
+
* @returns {Promise<fs.Stats>}
|
|
97
|
+
*/
|
|
98
|
+
download({ relativePath }: {
|
|
99
|
+
relativePath: string;
|
|
100
|
+
}): Promise<fs.Stats>;
|
|
101
|
+
}
|
|
102
|
+
export default RemoteFileSystem;
|