@lvce-editor/file-system-process 5.13.0 → 5.14.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/dist/index.js +31 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1696,6 +1696,36 @@ const getFileHash = async uri => {
|
|
|
1696
1696
|
throw new VError(error, `Failed to hash file "${uri}"`);
|
|
1697
1697
|
}
|
|
1698
1698
|
};
|
|
1699
|
+
const maxConcurrentFileHashes = 32;
|
|
1700
|
+
const getFileHashes = async uris => {
|
|
1701
|
+
if (!Array.isArray(uris)) {
|
|
1702
|
+
throw new TypeError('uris must be an array');
|
|
1703
|
+
}
|
|
1704
|
+
for (const uri of uris) {
|
|
1705
|
+
string(uri);
|
|
1706
|
+
assertUri(uri);
|
|
1707
|
+
}
|
|
1708
|
+
const hashes = [];
|
|
1709
|
+
for (let index = 0; index < uris.length; index++) {
|
|
1710
|
+
hashes.push(null);
|
|
1711
|
+
}
|
|
1712
|
+
let nextIndex = 0;
|
|
1713
|
+
const hashNext = async () => {
|
|
1714
|
+
while (nextIndex < uris.length) {
|
|
1715
|
+
const index = nextIndex++;
|
|
1716
|
+
try {
|
|
1717
|
+
hashes[index] = await getFileHash(uris[index]);
|
|
1718
|
+
} catch {
|
|
1719
|
+
hashes[index] = null;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
const workerCount = Math.min(maxConcurrentFileHashes, uris.length);
|
|
1724
|
+
await Promise.all(Array.from({
|
|
1725
|
+
length: workerCount
|
|
1726
|
+
}, hashNext));
|
|
1727
|
+
return hashes;
|
|
1728
|
+
};
|
|
1699
1729
|
const writeFile = async (uri, content, encoding = Utf8) => {
|
|
1700
1730
|
try {
|
|
1701
1731
|
assertUri(uri);
|
|
@@ -1947,6 +1977,7 @@ const commandMap = {
|
|
|
1947
1977
|
'FileSystem.copy': copy,
|
|
1948
1978
|
'FileSystem.exists': exists,
|
|
1949
1979
|
'FileSystem.getFileHash': getFileHash,
|
|
1980
|
+
'FileSystem.getFileHashes': getFileHashes,
|
|
1950
1981
|
'FileSystem.getFolderSize': getFolderSize,
|
|
1951
1982
|
'FileSystem.getPathSeparator': getPathSeparator,
|
|
1952
1983
|
'FileSystem.isReadonly': isReadonly,
|