访问字符串和二进制输出
Deno Sandboxes provide a sandboxed environment for evaluating JavaScript code. This is useful for evaluating code that is not trusted or for testing code that is not safe to run in the main runtime.
你可以访问沙箱中命令的字符串和二进制输出。
import { Sandbox } from "@deno/sandbox";
await using sandbox = await Sandbox.create();
// 获取字符串和二进制数据
const result = await sandbox.sh`cat binary-file.png`
.stdout("piped");
console.log("二进制长度:", result.stdout!.length);
console.log("文本长度:", result.stdoutText!.length);
// 使用二进制数据
import fs from "node:fs";
fs.writeFileSync("output.png", result.stdout!);
For more information about Sandboxes, see the Sandboxes documentation.