update deno common smod
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import {decodeBase64, encodeBase64} from "jsr:@std/encoding/base64";
|
||||
import {dirname, fromFileUrl} from "https://deno.land/std/path/mod.ts";
|
||||
import {spawn, SpawnOptionsWithoutStdio} from "node:child_process";
|
||||
import { readFile,readFileSync } from 'node:fs';
|
||||
|
||||
// reference: https://docs.deno.com/examples/hex_base64_encoding/
|
||||
// import { decodeBase64, encodeBase64 } from "jsr:@std/encoding/base64";
|
||||
@@ -773,6 +774,7 @@ export async function existsPath(path: string): Promise<boolean> {
|
||||
export async function readFileToString(
|
||||
filename: string,
|
||||
): Promise<string | null> {
|
||||
if (isDeno()) {
|
||||
try {
|
||||
return await Deno.readTextFile(resolveFilename(filename));
|
||||
} catch (e) {
|
||||
@@ -782,8 +784,19 @@ export async function readFileToString(
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return Promise((resolve, reject) => {
|
||||
readFile(resolveFilename(filename), 'utf8', (err, buffer) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(buffer);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function readFileToStringSync(filename: string): string | null {
|
||||
if (isDeno()) {
|
||||
try {
|
||||
return Deno.readTextFileSync(resolveFilename(filename));
|
||||
} catch (e) {
|
||||
@@ -793,6 +806,8 @@ export function readFileToStringSync(filename: string): string | null {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return readFileSync(resolveFilename(filename), 'utf8');
|
||||
}
|
||||
|
||||
export async function writeStringToFile(
|
||||
filename: string,
|
||||
|
||||
Reference in New Issue
Block a user