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