@lvce-editor/file-system-process 5.7.0 → 5.9.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 +1 -5
- package/dist/index.js +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { existsSync, constants } from 'node:fs';
|
|
2
3
|
import * as fs from 'node:fs/promises';
|
|
3
4
|
import * as os from 'node:os';
|
|
@@ -1674,6 +1675,20 @@ const readFile = async (uri, encoding = Utf8) => {
|
|
|
1674
1675
|
throw new VError(error, `Failed to read file "${uri}"`);
|
|
1675
1676
|
}
|
|
1676
1677
|
};
|
|
1678
|
+
const getFileHash = async uri => {
|
|
1679
|
+
try {
|
|
1680
|
+
string(uri);
|
|
1681
|
+
assertUri(uri);
|
|
1682
|
+
const path = fileURLToPath(uri);
|
|
1683
|
+
const content = await fs.readFile(path);
|
|
1684
|
+
return createHash('sha256').update(content).digest('hex');
|
|
1685
|
+
} catch (error) {
|
|
1686
|
+
if (isEnoentError(error)) {
|
|
1687
|
+
throw new FileNotFoundError(uri);
|
|
1688
|
+
}
|
|
1689
|
+
throw new VError(error, `Failed to hash file "${uri}"`);
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1677
1692
|
const writeFile = async (uri, content, encoding = Utf8) => {
|
|
1678
1693
|
try {
|
|
1679
1694
|
assertUri(uri);
|
|
@@ -1929,6 +1944,7 @@ const commandMap = {
|
|
|
1929
1944
|
'FileSystem.chmod': chmod,
|
|
1930
1945
|
'FileSystem.copy': copy,
|
|
1931
1946
|
'FileSystem.exists': exists,
|
|
1947
|
+
'FileSystem.getFileHash': getFileHash,
|
|
1932
1948
|
'FileSystem.getFolderSize': getFolderSize,
|
|
1933
1949
|
'FileSystem.getPathSeparator': getPathSeparator,
|
|
1934
1950
|
'FileSystem.isReadonly': isReadonly,
|