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= FileSystemLeft | Ok if (
E
.
isRight
(
result
)) {
// encoded "I ❤️ DuploJS" write with success }

Syntax

typescript
function writeFile(
  path: string | URL,
  data: Uint8Array
): Promise<FileSystemLeft | E.Ok>

Parameters

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

Return value

  • E.Ok : if the write succeeds.
  • FileSystemLeft : if the write fails.

See also

Released under the MIT license.