xshell 1.0.87 → 1.0.88

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.
Files changed (3) hide show
  1. package/file.d.ts +2 -0
  2. package/file.js +16 -0
  3. package/package.json +1 -1
package/file.d.ts CHANGED
@@ -51,6 +51,8 @@ export declare function fread_json<T = any>(fp: string, options?: {
51
51
  encoding?: Encoding;
52
52
  print?: boolean;
53
53
  }): Promise<T>;
54
+ /** 比较两个文件是否一致,遇到任何文件系统错误都返回 false */
55
+ export declare function fequals(fp_left: string, fp_right: string): Promise<boolean>;
54
56
  interface FWriteOptions {
55
57
  print?: boolean;
56
58
  }
package/file.js CHANGED
@@ -55,6 +55,22 @@ export async function fread_lines(fp, options = {}) {
55
55
  export async function fread_json(fp, options = {}) {
56
56
  return JSON.parse(await fread(fp, options));
57
57
  }
58
+ /** 比较两个文件是否一致,遇到任何文件系统错误都返回 false */
59
+ export async function fequals(fp_left, fp_right) {
60
+ try {
61
+ const fps = [fp_left, fp_right];
62
+ const [{ size: size_left }, { size: size_right }] = await Promise.all(fps.map(async (fp) => fstat(fp)));
63
+ if (size_left === size_right) {
64
+ const [data_left, data_right] = await Promise.all(fps.map(async (fp) => fread(fp, { encoding: 'binary' })));
65
+ return data_left.equals(data_right);
66
+ }
67
+ else
68
+ return false;
69
+ }
70
+ catch {
71
+ return false;
72
+ }
73
+ }
58
74
  export async function fwrite(fp, data, { print = true } = {}) {
59
75
  const is_handle = typeof fp === 'object' && fp && 'fd' in fp;
60
76
  if (is_handle) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.87",
3
+ "version": "1.0.88",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {