You can easily access your files in different formats (text, json, stream, etc...).

import { f0 } from "file0";
import { Readable } from "stream";
import fs from "fs";

// Get file metadata (name, size, public url, etc..)
const metadata = await f0.get("logs.txt");

// Download a text file
const text = await f0.get("hello.txt", { as: "text" });

// Download a json object
const obj = await f0.get("data.json", { as: "json" });

// Download as a stream and save to the file system
const fileStream = await f0.get("logs.txt", { as: "stream"});

// Download as a buffer
const file = await f0.get("image.png", { as: "buffer" });
// returns the web-compatible ArrayBuffer
// To convert it to a Node.js Buffer:
const nodejsBuffer = Buffer.from(file);

Last updated