Last active
September 30, 2022 23:28
-
-
Save antklim/0f81e517cb7361aeded3c4394f9b015a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readFile = async (file: string): Promise<[Error | null, string]> => { | |
try { | |
const text = await Deno.readTextFile(file); | |
return [null, text]; | |
} catch (err) { | |
return [err, ""]; | |
} | |
}; | |
const main = async () => { | |
const file = Deno.env.get("FILE"); | |
if (!file) { | |
console.log("file name required."); | |
return; | |
} | |
console.log(`reading ${file} ...`); | |
const [err, text] = await readFile(file); | |
if (err != null) { | |
console.error(`failed to read ${file}: ${err}`); | |
return; | |
} | |
console.log(`file content:\n${text}`); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment