update deno common smod

This commit is contained in:
2026-02-11 01:50:54 +08:00
parent 6ee6f0e2e6
commit b4ec83b4c3

View File

@@ -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) {
@@ -781,9 +783,20 @@ 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) {
@@ -792,6 +805,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(