@componentor/fs 1.2.4 → 1.2.6
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/dist/index.js +199 -236
- package/dist/index.js.map +1 -1
- package/dist/opfs-hybrid.js +199 -236
- package/dist/opfs-hybrid.js.map +1 -1
- package/dist/opfs-worker.js +199 -236
- package/dist/opfs-worker.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +26 -14
- package/src/packed-storage.ts +209 -262
- package/src/symlink-manager.ts +8 -5
package/dist/opfs-hybrid.js
CHANGED
|
@@ -403,12 +403,15 @@ var SymlinkManager = class {
|
|
|
403
403
|
const buffer = new TextEncoder().encode(data);
|
|
404
404
|
if (this.useSync) {
|
|
405
405
|
const access = await fileHandle.createSyncAccessHandle();
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
written
|
|
406
|
+
try {
|
|
407
|
+
access.truncate(0);
|
|
408
|
+
let written = 0;
|
|
409
|
+
while (written < buffer.length) {
|
|
410
|
+
written += access.write(buffer.subarray(written), { at: written });
|
|
411
|
+
}
|
|
412
|
+
} finally {
|
|
413
|
+
access.close();
|
|
410
414
|
}
|
|
411
|
-
access.close();
|
|
412
415
|
} else {
|
|
413
416
|
const writable = await fileHandle.createWritable();
|
|
414
417
|
await writable.write(buffer);
|
|
@@ -653,29 +656,12 @@ var PackedStorage = class {
|
|
|
653
656
|
useChecksum;
|
|
654
657
|
index = null;
|
|
655
658
|
indexLoaded = false;
|
|
656
|
-
lockPromise = null;
|
|
657
659
|
constructor(handleManager, useSync, useCompression = false, useChecksum = true) {
|
|
658
660
|
this.handleManager = handleManager;
|
|
659
661
|
this.useSync = useSync;
|
|
660
662
|
this.useCompression = useCompression && typeof CompressionStream !== "undefined";
|
|
661
663
|
this.useChecksum = useChecksum;
|
|
662
664
|
}
|
|
663
|
-
/**
|
|
664
|
-
* Acquire lock for pack file access (prevents concurrent handle conflicts)
|
|
665
|
-
*/
|
|
666
|
-
async acquireLock() {
|
|
667
|
-
while (this.lockPromise) {
|
|
668
|
-
await this.lockPromise;
|
|
669
|
-
}
|
|
670
|
-
let release;
|
|
671
|
-
this.lockPromise = new Promise((resolve) => {
|
|
672
|
-
release = () => {
|
|
673
|
-
this.lockPromise = null;
|
|
674
|
-
resolve();
|
|
675
|
-
};
|
|
676
|
-
});
|
|
677
|
-
return release;
|
|
678
|
-
}
|
|
679
665
|
/**
|
|
680
666
|
* Reset pack storage state (memory only)
|
|
681
667
|
*/
|
|
@@ -759,62 +745,47 @@ var PackedStorage = class {
|
|
|
759
745
|
* Check if a path exists in the pack
|
|
760
746
|
*/
|
|
761
747
|
async has(path) {
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
const index = await this.loadIndex();
|
|
765
|
-
return path in index;
|
|
766
|
-
} finally {
|
|
767
|
-
release();
|
|
768
|
-
}
|
|
748
|
+
const index = await this.loadIndex();
|
|
749
|
+
return path in index;
|
|
769
750
|
}
|
|
770
751
|
/**
|
|
771
752
|
* Get file size from pack (for stat)
|
|
772
753
|
* Returns originalSize if compressed, otherwise size
|
|
773
754
|
*/
|
|
774
755
|
async getSize(path) {
|
|
775
|
-
const
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
if (!entry) return null;
|
|
780
|
-
return entry.originalSize ?? entry.size;
|
|
781
|
-
} finally {
|
|
782
|
-
release();
|
|
783
|
-
}
|
|
756
|
+
const index = await this.loadIndex();
|
|
757
|
+
const entry = index[path];
|
|
758
|
+
if (!entry) return null;
|
|
759
|
+
return entry.originalSize ?? entry.size;
|
|
784
760
|
}
|
|
785
761
|
/**
|
|
786
762
|
* Read a file from the pack
|
|
787
763
|
* Handles decompression if file was stored compressed
|
|
788
764
|
*/
|
|
789
765
|
async read(path) {
|
|
790
|
-
const
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
} finally {
|
|
804
|
-
access.close();
|
|
805
|
-
}
|
|
806
|
-
} else {
|
|
807
|
-
const file = await fileHandle.getFile();
|
|
808
|
-
const data = new Uint8Array(await file.arrayBuffer());
|
|
809
|
-
buffer = data.slice(entry.offset, entry.offset + entry.size);
|
|
810
|
-
}
|
|
811
|
-
if (entry.originalSize !== void 0) {
|
|
812
|
-
return decompress(buffer);
|
|
766
|
+
const index = await this.loadIndex();
|
|
767
|
+
const entry = index[path];
|
|
768
|
+
if (!entry) return null;
|
|
769
|
+
const { fileHandle } = await this.handleManager.getHandle(PACK_FILE);
|
|
770
|
+
if (!fileHandle) return null;
|
|
771
|
+
let buffer;
|
|
772
|
+
if (this.useSync) {
|
|
773
|
+
const access = await fileHandle.createSyncAccessHandle();
|
|
774
|
+
try {
|
|
775
|
+
buffer = new Uint8Array(entry.size);
|
|
776
|
+
access.read(buffer, { at: entry.offset });
|
|
777
|
+
} finally {
|
|
778
|
+
access.close();
|
|
813
779
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
780
|
+
} else {
|
|
781
|
+
const file = await fileHandle.getFile();
|
|
782
|
+
const data = new Uint8Array(await file.arrayBuffer());
|
|
783
|
+
buffer = data.slice(entry.offset, entry.offset + entry.size);
|
|
817
784
|
}
|
|
785
|
+
if (entry.originalSize !== void 0) {
|
|
786
|
+
return decompress(buffer);
|
|
787
|
+
}
|
|
788
|
+
return buffer;
|
|
818
789
|
}
|
|
819
790
|
/**
|
|
820
791
|
* Read multiple files from the pack in a single operation
|
|
@@ -824,61 +795,56 @@ var PackedStorage = class {
|
|
|
824
795
|
async readBatch(paths) {
|
|
825
796
|
const results = /* @__PURE__ */ new Map();
|
|
826
797
|
if (paths.length === 0) return results;
|
|
827
|
-
const
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
} else {
|
|
836
|
-
results.set(path, null);
|
|
837
|
-
}
|
|
798
|
+
const index = await this.loadIndex();
|
|
799
|
+
const toRead = [];
|
|
800
|
+
for (const path of paths) {
|
|
801
|
+
const entry = index[path];
|
|
802
|
+
if (entry) {
|
|
803
|
+
toRead.push({ path, offset: entry.offset, size: entry.size, originalSize: entry.originalSize });
|
|
804
|
+
} else {
|
|
805
|
+
results.set(path, null);
|
|
838
806
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
return results;
|
|
807
|
+
}
|
|
808
|
+
if (toRead.length === 0) return results;
|
|
809
|
+
const { fileHandle } = await this.handleManager.getHandle(PACK_FILE);
|
|
810
|
+
if (!fileHandle) {
|
|
811
|
+
for (const { path } of toRead) {
|
|
812
|
+
results.set(path, null);
|
|
846
813
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
access.read(buffer, { at: offset });
|
|
854
|
-
if (originalSize !== void 0) {
|
|
855
|
-
decompressPromises.push({ path, promise: decompress(buffer) });
|
|
856
|
-
} else {
|
|
857
|
-
results.set(path, buffer);
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
} finally {
|
|
861
|
-
access.close();
|
|
862
|
-
}
|
|
863
|
-
} else {
|
|
864
|
-
const file = await fileHandle.getFile();
|
|
865
|
-
const data = new Uint8Array(await file.arrayBuffer());
|
|
814
|
+
return results;
|
|
815
|
+
}
|
|
816
|
+
const decompressPromises = [];
|
|
817
|
+
if (this.useSync) {
|
|
818
|
+
const access = await fileHandle.createSyncAccessHandle();
|
|
819
|
+
try {
|
|
866
820
|
for (const { path, offset, size, originalSize } of toRead) {
|
|
867
|
-
const buffer =
|
|
821
|
+
const buffer = new Uint8Array(size);
|
|
822
|
+
access.read(buffer, { at: offset });
|
|
868
823
|
if (originalSize !== void 0) {
|
|
869
824
|
decompressPromises.push({ path, promise: decompress(buffer) });
|
|
870
825
|
} else {
|
|
871
826
|
results.set(path, buffer);
|
|
872
827
|
}
|
|
873
828
|
}
|
|
829
|
+
} finally {
|
|
830
|
+
access.close();
|
|
874
831
|
}
|
|
875
|
-
|
|
876
|
-
|
|
832
|
+
} else {
|
|
833
|
+
const file = await fileHandle.getFile();
|
|
834
|
+
const data = new Uint8Array(await file.arrayBuffer());
|
|
835
|
+
for (const { path, offset, size, originalSize } of toRead) {
|
|
836
|
+
const buffer = data.slice(offset, offset + size);
|
|
837
|
+
if (originalSize !== void 0) {
|
|
838
|
+
decompressPromises.push({ path, promise: decompress(buffer) });
|
|
839
|
+
} else {
|
|
840
|
+
results.set(path, buffer);
|
|
841
|
+
}
|
|
877
842
|
}
|
|
878
|
-
return results;
|
|
879
|
-
} finally {
|
|
880
|
-
release();
|
|
881
843
|
}
|
|
844
|
+
for (const { path, promise } of decompressPromises) {
|
|
845
|
+
results.set(path, await promise);
|
|
846
|
+
}
|
|
847
|
+
return results;
|
|
882
848
|
}
|
|
883
849
|
/**
|
|
884
850
|
* Write multiple files to the pack in a single operation
|
|
@@ -889,62 +855,57 @@ var PackedStorage = class {
|
|
|
889
855
|
*/
|
|
890
856
|
async writeBatch(entries) {
|
|
891
857
|
if (entries.length === 0) return;
|
|
892
|
-
const
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
if (compressed.length < data.length) {
|
|
901
|
-
return { path, data: compressed, originalSize: data.length };
|
|
902
|
-
}
|
|
903
|
-
return { path, data };
|
|
904
|
-
})
|
|
905
|
-
);
|
|
906
|
-
} else {
|
|
907
|
-
processedEntries = entries;
|
|
908
|
-
}
|
|
909
|
-
let totalDataSize = 0;
|
|
910
|
-
for (const { data } of processedEntries) {
|
|
911
|
-
totalDataSize += data.length;
|
|
912
|
-
}
|
|
913
|
-
const newIndex = {};
|
|
914
|
-
let headerSize = 8;
|
|
915
|
-
let prevHeaderSize = 0;
|
|
916
|
-
while (headerSize !== prevHeaderSize) {
|
|
917
|
-
prevHeaderSize = headerSize;
|
|
918
|
-
let currentOffset = headerSize;
|
|
919
|
-
for (const { path, data, originalSize } of processedEntries) {
|
|
920
|
-
const entry = { offset: currentOffset, size: data.length };
|
|
921
|
-
if (originalSize !== void 0) {
|
|
922
|
-
entry.originalSize = originalSize;
|
|
858
|
+
const encoder = new TextEncoder();
|
|
859
|
+
let processedEntries;
|
|
860
|
+
if (this.useCompression) {
|
|
861
|
+
processedEntries = await Promise.all(
|
|
862
|
+
entries.map(async ({ path, data }) => {
|
|
863
|
+
const compressed = await compress(data);
|
|
864
|
+
if (compressed.length < data.length) {
|
|
865
|
+
return { path, data: compressed, originalSize: data.length };
|
|
923
866
|
}
|
|
924
|
-
|
|
925
|
-
|
|
867
|
+
return { path, data };
|
|
868
|
+
})
|
|
869
|
+
);
|
|
870
|
+
} else {
|
|
871
|
+
processedEntries = entries;
|
|
872
|
+
}
|
|
873
|
+
let totalDataSize = 0;
|
|
874
|
+
for (const { data } of processedEntries) {
|
|
875
|
+
totalDataSize += data.length;
|
|
876
|
+
}
|
|
877
|
+
const newIndex = {};
|
|
878
|
+
let headerSize = 8;
|
|
879
|
+
let prevHeaderSize = 0;
|
|
880
|
+
while (headerSize !== prevHeaderSize) {
|
|
881
|
+
prevHeaderSize = headerSize;
|
|
882
|
+
let currentOffset = headerSize;
|
|
883
|
+
for (const { path, data, originalSize } of processedEntries) {
|
|
884
|
+
const entry = { offset: currentOffset, size: data.length };
|
|
885
|
+
if (originalSize !== void 0) {
|
|
886
|
+
entry.originalSize = originalSize;
|
|
926
887
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
}
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
view.setUint32(0, finalIndexBuf.length, true);
|
|
942
|
-
view.setUint32(4, checksum, true);
|
|
943
|
-
await this.writePackFile(packBuffer);
|
|
944
|
-
this.index = newIndex;
|
|
945
|
-
} finally {
|
|
946
|
-
release();
|
|
888
|
+
newIndex[path] = entry;
|
|
889
|
+
currentOffset += data.length;
|
|
890
|
+
}
|
|
891
|
+
const indexBuf = encoder.encode(JSON.stringify(newIndex));
|
|
892
|
+
headerSize = 8 + indexBuf.length;
|
|
893
|
+
}
|
|
894
|
+
const finalIndexBuf = encoder.encode(JSON.stringify(newIndex));
|
|
895
|
+
const totalSize = headerSize + totalDataSize;
|
|
896
|
+
const packBuffer = new Uint8Array(totalSize);
|
|
897
|
+
const view = new DataView(packBuffer.buffer);
|
|
898
|
+
packBuffer.set(finalIndexBuf, 8);
|
|
899
|
+
for (const { path, data } of processedEntries) {
|
|
900
|
+
const entry = newIndex[path];
|
|
901
|
+
packBuffer.set(data, entry.offset);
|
|
947
902
|
}
|
|
903
|
+
const content = packBuffer.subarray(8);
|
|
904
|
+
const checksum = this.useChecksum ? crc32(content) : 0;
|
|
905
|
+
view.setUint32(0, finalIndexBuf.length, true);
|
|
906
|
+
view.setUint32(4, checksum, true);
|
|
907
|
+
await this.writePackFile(packBuffer);
|
|
908
|
+
this.index = newIndex;
|
|
948
909
|
}
|
|
949
910
|
/**
|
|
950
911
|
* Write the pack file to OPFS
|
|
@@ -972,82 +933,72 @@ var PackedStorage = class {
|
|
|
972
933
|
* Note: Doesn't reclaim space, just removes from index and recalculates CRC32
|
|
973
934
|
*/
|
|
974
935
|
async remove(path) {
|
|
975
|
-
const
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
const
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
access.read(oldHeader, { at: 0 });
|
|
990
|
-
const oldIndexLen = new DataView(oldHeader.buffer).getUint32(0, true);
|
|
991
|
-
const dataStart = 8 + oldIndexLen;
|
|
992
|
-
const dataSize = size - dataStart;
|
|
993
|
-
const dataPortion = new Uint8Array(dataSize);
|
|
994
|
-
if (dataSize > 0) {
|
|
995
|
-
access.read(dataPortion, { at: dataStart });
|
|
996
|
-
}
|
|
997
|
-
const newContent = new Uint8Array(newIndexBuf.length + dataSize);
|
|
998
|
-
newContent.set(newIndexBuf, 0);
|
|
999
|
-
if (dataSize > 0) {
|
|
1000
|
-
newContent.set(dataPortion, newIndexBuf.length);
|
|
1001
|
-
}
|
|
1002
|
-
const checksum = this.useChecksum ? crc32(newContent) : 0;
|
|
1003
|
-
const newHeader = new Uint8Array(8);
|
|
1004
|
-
const view = new DataView(newHeader.buffer);
|
|
1005
|
-
view.setUint32(0, newIndexBuf.length, true);
|
|
1006
|
-
view.setUint32(4, checksum, true);
|
|
1007
|
-
const newFile = new Uint8Array(8 + newContent.length);
|
|
1008
|
-
newFile.set(newHeader, 0);
|
|
1009
|
-
newFile.set(newContent, 8);
|
|
1010
|
-
access.truncate(newFile.length);
|
|
1011
|
-
access.write(newFile, { at: 0 });
|
|
1012
|
-
} finally {
|
|
1013
|
-
access.close();
|
|
1014
|
-
}
|
|
1015
|
-
} else {
|
|
1016
|
-
const file = await fileHandle.getFile();
|
|
1017
|
-
const oldData = new Uint8Array(await file.arrayBuffer());
|
|
1018
|
-
if (oldData.length < 8) return true;
|
|
1019
|
-
const oldIndexLen = new DataView(oldData.buffer).getUint32(0, true);
|
|
936
|
+
const index = await this.loadIndex();
|
|
937
|
+
if (!(path in index)) return false;
|
|
938
|
+
delete index[path];
|
|
939
|
+
const { fileHandle } = await this.handleManager.getHandle(PACK_FILE);
|
|
940
|
+
if (!fileHandle) return true;
|
|
941
|
+
const encoder = new TextEncoder();
|
|
942
|
+
const newIndexBuf = encoder.encode(JSON.stringify(index));
|
|
943
|
+
if (this.useSync) {
|
|
944
|
+
const access = await fileHandle.createSyncAccessHandle();
|
|
945
|
+
try {
|
|
946
|
+
const size = access.getSize();
|
|
947
|
+
const oldHeader = new Uint8Array(8);
|
|
948
|
+
access.read(oldHeader, { at: 0 });
|
|
949
|
+
const oldIndexLen = new DataView(oldHeader.buffer).getUint32(0, true);
|
|
1020
950
|
const dataStart = 8 + oldIndexLen;
|
|
1021
|
-
const
|
|
1022
|
-
const
|
|
951
|
+
const dataSize = size - dataStart;
|
|
952
|
+
const dataPortion = new Uint8Array(dataSize);
|
|
953
|
+
if (dataSize > 0) {
|
|
954
|
+
access.read(dataPortion, { at: dataStart });
|
|
955
|
+
}
|
|
956
|
+
const newContent = new Uint8Array(newIndexBuf.length + dataSize);
|
|
1023
957
|
newContent.set(newIndexBuf, 0);
|
|
1024
|
-
|
|
958
|
+
if (dataSize > 0) {
|
|
959
|
+
newContent.set(dataPortion, newIndexBuf.length);
|
|
960
|
+
}
|
|
1025
961
|
const checksum = this.useChecksum ? crc32(newContent) : 0;
|
|
1026
|
-
const
|
|
1027
|
-
const view = new DataView(
|
|
962
|
+
const newHeader = new Uint8Array(8);
|
|
963
|
+
const view = new DataView(newHeader.buffer);
|
|
1028
964
|
view.setUint32(0, newIndexBuf.length, true);
|
|
1029
965
|
view.setUint32(4, checksum, true);
|
|
966
|
+
const newFile = new Uint8Array(8 + newContent.length);
|
|
967
|
+
newFile.set(newHeader, 0);
|
|
1030
968
|
newFile.set(newContent, 8);
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
969
|
+
access.truncate(newFile.length);
|
|
970
|
+
access.write(newFile, { at: 0 });
|
|
971
|
+
} finally {
|
|
972
|
+
access.close();
|
|
1034
973
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
974
|
+
} else {
|
|
975
|
+
const file = await fileHandle.getFile();
|
|
976
|
+
const oldData = new Uint8Array(await file.arrayBuffer());
|
|
977
|
+
if (oldData.length < 8) return true;
|
|
978
|
+
const oldIndexLen = new DataView(oldData.buffer).getUint32(0, true);
|
|
979
|
+
const dataStart = 8 + oldIndexLen;
|
|
980
|
+
const dataPortion = oldData.subarray(dataStart);
|
|
981
|
+
const newContent = new Uint8Array(newIndexBuf.length + dataPortion.length);
|
|
982
|
+
newContent.set(newIndexBuf, 0);
|
|
983
|
+
newContent.set(dataPortion, newIndexBuf.length);
|
|
984
|
+
const checksum = this.useChecksum ? crc32(newContent) : 0;
|
|
985
|
+
const newFile = new Uint8Array(8 + newContent.length);
|
|
986
|
+
const view = new DataView(newFile.buffer);
|
|
987
|
+
view.setUint32(0, newIndexBuf.length, true);
|
|
988
|
+
view.setUint32(4, checksum, true);
|
|
989
|
+
newFile.set(newContent, 8);
|
|
990
|
+
const writable = await fileHandle.createWritable();
|
|
991
|
+
await writable.write(newFile);
|
|
992
|
+
await writable.close();
|
|
1038
993
|
}
|
|
994
|
+
return true;
|
|
1039
995
|
}
|
|
1040
996
|
/**
|
|
1041
997
|
* Check if pack file is being used (has entries)
|
|
1042
998
|
*/
|
|
1043
999
|
async isEmpty() {
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1046
|
-
const index = await this.loadIndex();
|
|
1047
|
-
return Object.keys(index).length === 0;
|
|
1048
|
-
} finally {
|
|
1049
|
-
release();
|
|
1050
|
-
}
|
|
1000
|
+
const index = await this.loadIndex();
|
|
1001
|
+
return Object.keys(index).length === 0;
|
|
1051
1002
|
}
|
|
1052
1003
|
};
|
|
1053
1004
|
|
|
@@ -1284,10 +1235,13 @@ var OPFS = class {
|
|
|
1284
1235
|
let buffer;
|
|
1285
1236
|
if (this.useSync) {
|
|
1286
1237
|
const access = await fileHandle.createSyncAccessHandle();
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1238
|
+
try {
|
|
1239
|
+
const size = access.getSize();
|
|
1240
|
+
buffer = new Uint8Array(size);
|
|
1241
|
+
access.read(buffer);
|
|
1242
|
+
} finally {
|
|
1243
|
+
access.close();
|
|
1244
|
+
}
|
|
1291
1245
|
} else {
|
|
1292
1246
|
const file = await fileHandle.getFile();
|
|
1293
1247
|
buffer = new Uint8Array(await file.arrayBuffer());
|
|
@@ -1345,10 +1299,13 @@ var OPFS = class {
|
|
|
1345
1299
|
let buffer;
|
|
1346
1300
|
if (this.useSync) {
|
|
1347
1301
|
const access = await fileHandle.createSyncAccessHandle();
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1302
|
+
try {
|
|
1303
|
+
const size = access.getSize();
|
|
1304
|
+
buffer = new Uint8Array(size);
|
|
1305
|
+
access.read(buffer);
|
|
1306
|
+
} finally {
|
|
1307
|
+
access.close();
|
|
1308
|
+
}
|
|
1352
1309
|
} else {
|
|
1353
1310
|
const file = await fileHandle.getFile();
|
|
1354
1311
|
buffer = new Uint8Array(await file.arrayBuffer());
|
|
@@ -1381,9 +1338,12 @@ var OPFS = class {
|
|
|
1381
1338
|
const buffer = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
1382
1339
|
if (this.useSync) {
|
|
1383
1340
|
const access = await fileHandle.createSyncAccessHandle();
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1341
|
+
try {
|
|
1342
|
+
access.truncate(buffer.length);
|
|
1343
|
+
access.write(buffer, { at: 0 });
|
|
1344
|
+
} finally {
|
|
1345
|
+
access.close();
|
|
1346
|
+
}
|
|
1387
1347
|
} else {
|
|
1388
1348
|
const writable = await fileHandle.createWritable();
|
|
1389
1349
|
await writable.write(buffer);
|
|
@@ -1997,8 +1957,11 @@ var OPFS = class {
|
|
|
1997
1957
|
if (!fileHandle) throw createENOENT(path);
|
|
1998
1958
|
if (this.useSync) {
|
|
1999
1959
|
const access = await fileHandle.createSyncAccessHandle();
|
|
2000
|
-
|
|
2001
|
-
|
|
1960
|
+
try {
|
|
1961
|
+
access.truncate(len);
|
|
1962
|
+
} finally {
|
|
1963
|
+
access.close();
|
|
1964
|
+
}
|
|
2002
1965
|
} else {
|
|
2003
1966
|
const file = await fileHandle.getFile();
|
|
2004
1967
|
const data = new Uint8Array(await file.arrayBuffer());
|