@open-audio-stack/core 0.0.8 → 0.0.10
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/build/helpers/file.d.ts +2 -1
- package/build/helpers/file.js +9 -3
- package/build/index-browser.d.ts +1 -0
- package/build/index-browser.js +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +1 -1
package/build/helpers/file.d.ts
CHANGED
|
@@ -19,9 +19,10 @@ export declare function fileDelete(filePath: string): boolean | void;
|
|
|
19
19
|
export declare function fileExec(filePath: string): void;
|
|
20
20
|
export declare function fileExists(filePath: string): boolean;
|
|
21
21
|
export declare function fileJsonCreate(filePath: string, data: object): void;
|
|
22
|
+
export declare function fileHash(filePath: string, algorithm?: string): string;
|
|
22
23
|
export declare function fileMove(filePath: string, newPath: string): void | boolean;
|
|
23
24
|
export declare function fileOpen(filePath: string): Buffer;
|
|
24
|
-
export declare function fileRead(filePath: string):
|
|
25
|
+
export declare function fileRead(filePath: string): string;
|
|
25
26
|
export declare function fileReadJson(filePath: string): any;
|
|
26
27
|
export declare function fileReadString(filePath: string): string;
|
|
27
28
|
export declare function fileReadYaml(filePath: string): unknown;
|
package/build/helpers/file.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import AdmZip from 'adm-zip';
|
|
2
2
|
import { execSync } from 'child_process';
|
|
3
3
|
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'fs';
|
|
4
|
+
import { createHash } from 'crypto';
|
|
4
5
|
import { globSync } from 'glob';
|
|
5
6
|
import { moveSync } from 'fs-extra/esm';
|
|
6
7
|
import os from 'os';
|
|
@@ -125,6 +126,11 @@ export function fileExists(filePath) {
|
|
|
125
126
|
export function fileJsonCreate(filePath, data) {
|
|
126
127
|
return fileCreate(filePath, JSON.stringify(data, null, 2));
|
|
127
128
|
}
|
|
129
|
+
export function fileHash(filePath, algorithm = 'sha256') {
|
|
130
|
+
const fileData = fileReadString(filePath);
|
|
131
|
+
const fileNormalized = fileData.replace(/\r\n/g, '\n');
|
|
132
|
+
return createHash(algorithm).update(fileNormalized, 'utf8').digest('hex');
|
|
133
|
+
}
|
|
128
134
|
export function fileMove(filePath, newPath) {
|
|
129
135
|
if (fileExists(filePath)) {
|
|
130
136
|
console.log('-', filePath);
|
|
@@ -148,18 +154,18 @@ export function fileOpen(filePath) {
|
|
|
148
154
|
}
|
|
149
155
|
export function fileRead(filePath) {
|
|
150
156
|
console.log('⎋', filePath);
|
|
151
|
-
return readFileSync(filePath);
|
|
157
|
+
return readFileSync(filePath, 'utf8');
|
|
152
158
|
}
|
|
153
159
|
export function fileReadJson(filePath) {
|
|
154
160
|
if (fileExists(filePath)) {
|
|
155
161
|
console.log('⎋', filePath);
|
|
156
|
-
return JSON.parse(readFileSync(filePath).toString());
|
|
162
|
+
return JSON.parse(readFileSync(filePath, 'utf8').toString());
|
|
157
163
|
}
|
|
158
164
|
return false;
|
|
159
165
|
}
|
|
160
166
|
export function fileReadString(filePath) {
|
|
161
167
|
console.log('⎋', filePath);
|
|
162
|
-
return readFileSync(filePath).toString();
|
|
168
|
+
return readFileSync(filePath, 'utf8').toString();
|
|
163
169
|
}
|
|
164
170
|
export function fileReadYaml(filePath) {
|
|
165
171
|
const file = fileReadString(filePath);
|
package/build/index-browser.d.ts
CHANGED
package/build/index-browser.js
CHANGED
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED