summaryrefslogtreecommitdiff
path: root/fs/write_file_str.ts
diff options
context:
space:
mode:
authorAxetroy <troy450409405@gmail.com>2019-04-15 04:14:57 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-04-14 16:14:57 -0400
commit73368006586164e92089f639c61db9c0735586a6 (patch)
treeb33b36d7bd14c55c95624cf3e42b798c8124dd78 /fs/write_file_str.ts
parentd2d5b6ac8e25bc2046b1960b9a1d22e219299cb9 (diff)
add writeFileStr and update documentation (denoland/deno_std#340)
Original: https://github.com/denoland/deno_std/commit/191e53a78bfc96d32df6d01affa90f938b92e6e5
Diffstat (limited to 'fs/write_file_str.ts')
-rw-r--r--fs/write_file_str.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/fs/write_file_str.ts b/fs/write_file_str.ts
new file mode 100644
index 000000000..a4a4beb5b
--- /dev/null
+++ b/fs/write_file_str.ts
@@ -0,0 +1,28 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+
+/**
+ * Write the string to file synchronously.
+ *
+ * @param filename File to write
+ * @param content The content write to file
+ * @returns void
+ */
+export function writeFileStrSync(filename: string, content: string): void {
+ const encoder = new TextEncoder();
+ Deno.writeFileSync(filename, encoder.encode(content));
+}
+
+/**
+ * Write the string to file.
+ *
+ * @param filename File to write
+ * @param content The content write to file
+ * @returns Promise<void>
+ */
+export async function writeFileStr(
+ filename: string,
+ content: string
+): Promise<void> {
+ const encoder = new TextEncoder();
+ await Deno.writeFile(filename, encoder.encode(content));
+}