@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 CHANGED
@@ -1,7 +1,3 @@
1
1
  # File System Process
2
2
 
3
- File System Process
4
-
5
- ## Gitpod
6
-
7
- [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/lvce-editor/file-system-process)
3
+ File System Process
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-process",
3
- "version": "5.7.0",
3
+ "version": "5.9.0",
4
4
  "description": "File System Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",