sliftutils 0.46.0 → 0.48.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.
package/package.json
CHANGED
|
@@ -10,6 +10,20 @@ import { getFileStorageIndexDB } from "./IndexedDBFileFolderAPI";
|
|
|
10
10
|
import fs from "fs";
|
|
11
11
|
import path from "path";
|
|
12
12
|
|
|
13
|
+
interface Window {
|
|
14
|
+
showSaveFilePicker(config?: {
|
|
15
|
+
types: {
|
|
16
|
+
description: string; accept: { [mimeType: string]: string[] }
|
|
17
|
+
}[];
|
|
18
|
+
}): Promise<FileSystemFileHandle>;
|
|
19
|
+
showDirectoryPicker(): Promise<FileSystemDirectoryHandle>;
|
|
20
|
+
showOpenFilePicker(config?: {
|
|
21
|
+
types: {
|
|
22
|
+
description: string; accept: { [mimeType: string]: string[] }
|
|
23
|
+
}[];
|
|
24
|
+
}): Promise<FileSystemFileHandle[]>;
|
|
25
|
+
}
|
|
26
|
+
|
|
13
27
|
// NOTE: IndexedDB is required for iOS, at least. We MIGHT want to make
|
|
14
28
|
// this a user supported toggle too, so they can choose during runtime if they want it.
|
|
15
29
|
// DO NOT enable this is isNode
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { PromiseObj, compareArray, sort, throttleFunction, timeInMinute } from "socket-function/src/misc";
|
|
2
2
|
import { IStorage, IStorageRaw } from "./IStorage";
|
|
3
3
|
import { Zip } from "../misc/zip";
|
|
4
|
-
import { runInSerial } from "socket-function/src/batching";
|
|
4
|
+
import { delay, runInSerial } from "socket-function/src/batching";
|
|
5
5
|
import { formatNumber, formatTime } from "socket-function/src/formatting/format";
|
|
6
6
|
import { setPending } from "./PendingManager";
|
|
7
7
|
import { isInBuild } from "../misc/environment";
|
|
8
|
+
import { isNode } from "typesafecss";
|
|
8
9
|
|
|
9
10
|
/*
|
|
10
11
|
// Spec:
|
|
@@ -466,8 +467,10 @@ export class TransactionStorage implements IStorage<Buffer> {
|
|
|
466
467
|
|
|
467
468
|
let newChunks = this.chunkBuffers(buffers);
|
|
468
469
|
|
|
470
|
+
let newFiles: string[] = [];
|
|
469
471
|
for (let chunk of newChunks) {
|
|
470
472
|
let file = this.getCurrentChunk();
|
|
473
|
+
newFiles.push(file);
|
|
471
474
|
this.currentChunk = undefined;
|
|
472
475
|
let content = chunk.buffer;
|
|
473
476
|
let { header, headerBuffer } = this.getHeader(
|
|
@@ -479,6 +482,22 @@ export class TransactionStorage implements IStorage<Buffer> {
|
|
|
479
482
|
}
|
|
480
483
|
let buffer = Buffer.concat([headerBuffer, content]);
|
|
481
484
|
await this.rawStorage.set(file, buffer);
|
|
485
|
+
let verified = await this.rawStorage.get(file);
|
|
486
|
+
if (!verified?.equals(buffer)) {
|
|
487
|
+
console.error(`Failed to verify transaction file ${file} in ${this.debugName}`);
|
|
488
|
+
throw new Error(`Failed to verify transaction file ${file} in ${this.debugName}`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// Delay, because we want to be absolutely certain that all the writes have finished before deleting the old files.
|
|
492
|
+
await delay(5000);
|
|
493
|
+
if (!isNode()) {
|
|
494
|
+
localStorage.setItem(`${this.debugName}-last-compress`, JSON.stringify({
|
|
495
|
+
time: Date.now(),
|
|
496
|
+
entryCount: this.entryCount,
|
|
497
|
+
cacheSize: this.cache.size,
|
|
498
|
+
newFiles,
|
|
499
|
+
existingDiskEntries,
|
|
500
|
+
}));
|
|
482
501
|
}
|
|
483
502
|
|
|
484
503
|
// This is the ONLY time we can delete old files, as we know for sure the new file has all of our data.
|