Skip to content

writeFile

Writes binary content to a file.

Example

ts
import { 
SF
} from "@duplojs/server-utils";
import {
E
} from "@duplojs/utils";
const
encodedText
= new
TextEncoder
().
encode
("I ❤️ DuploJS");
const
result
= await
SF
.
writeFile
("/tmp/file.bin",
encodedText
);
// result= SF.FileSystemLeft<"write-file"> | Ok if (
E
.
isRight
(
result
)) {
// encoded "I ❤️ DuploJS" write with success }

Syntax

typescript
function writeFile(
  path: string,
  data: Uint8Array
): Promise<FileSystemLeft<"write-file"> | E.Ok>

Parameters

  • path : target file path.
  • data : binary content to write.

Return value

  • E.Ok : if the write succeeds.
  • FileSystemLeft<"write-file"> : if the write fails.

See also

Released under the MIT license.