mirror of
https://github.com/bitwarden/clients.git
synced 2026-07-10 21:03:56 +08:00
* Migrate cryptofunction service and remove old crypto * Fix tests and linting * Update libs/node/src/services/node-crypto-function.service.ts Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> * Update libs/node/src/services/node-crypto-function.service.ts Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> * Remove non-null assertion * Fix build * Prettier * Update libs/node/src/services/node-crypto-function.service.ts Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> --------- Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import * as fs from "fs";
|
|
import * as path from "path";
|
|
import * as readline from "readline";
|
|
|
|
export class NodeUtils {
|
|
static mkdirpSync(targetDir: string, mode = "700", relative = false, relativeDir: string = null) {
|
|
const initialDir = path.isAbsolute(targetDir) ? path.sep : "";
|
|
const baseDir = relative ? (relativeDir != null ? relativeDir : __dirname) : ".";
|
|
targetDir.split(path.sep).reduce((parentDir, childDir) => {
|
|
const dir = path.resolve(baseDir, parentDir, childDir);
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir, mode);
|
|
}
|
|
return dir;
|
|
}, initialDir);
|
|
}
|
|
static readFirstLine(fileName: string) {
|
|
return new Promise<string>((resolve, reject) => {
|
|
const readStream = fs.createReadStream(fileName, { encoding: "utf8" });
|
|
const readInterface = readline.createInterface(readStream);
|
|
readInterface
|
|
.on("line", (line) => {
|
|
readStream.close();
|
|
resolve(line);
|
|
})
|
|
.on("error", (err) => reject(err));
|
|
});
|
|
}
|
|
|
|
// https://stackoverflow.com/a/31394257
|
|
static bufferToArrayBuffer(buf: Buffer<ArrayBuffer>): ArrayBuffer {
|
|
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
}
|
|
}
|