@lvce-editor/file-system-process 5.13.0 → 5.15.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/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # File System Process
2
2
 
3
- File System Process
3
+ File System Process
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);
@@ -1767,6 +1797,22 @@ const remove = async uri => {
1767
1797
  throw new VError(error, `Failed to remove "${uri}"`);
1768
1798
  }
1769
1799
  };
1800
+ const forceRemove = async uri => {
1801
+ assertUri(uri);
1802
+ const path = fileURLToPath(uri);
1803
+ if (!isOkayToRemove(path)) {
1804
+ throw new Error('Cannot remove a filesystem root or home directory');
1805
+ }
1806
+ try {
1807
+ const stats = await fs.lstat(path);
1808
+ await fs.rm(path, {
1809
+ force: false,
1810
+ recursive: stats.isDirectory() && !stats.isSymbolicLink()
1811
+ });
1812
+ } catch (error) {
1813
+ throw new VError(error, `Failed to permanently remove "${uri}"`);
1814
+ }
1815
+ };
1770
1816
  const toPrettyDirent = dirent => {
1771
1817
  return {
1772
1818
  name: dirent.name,
@@ -1946,7 +1992,9 @@ const commandMap = {
1946
1992
  'FileSystem.chmod': chmod,
1947
1993
  'FileSystem.copy': copy,
1948
1994
  'FileSystem.exists': exists,
1995
+ 'FileSystem.forceRemove': forceRemove,
1949
1996
  'FileSystem.getFileHash': getFileHash,
1997
+ 'FileSystem.getFileHashes': getFileHashes,
1950
1998
  'FileSystem.getFolderSize': getFolderSize,
1951
1999
  'FileSystem.getPathSeparator': getPathSeparator,
1952
2000
  'FileSystem.isReadonly': isReadonly,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-process",
3
- "version": "5.13.0",
3
+ "version": "5.15.0",
4
4
  "description": "File System Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",