mock-file
Some filesystem APIs cannot be used with deno deploy (eg Deno.readFileSync
,
Deno.writeFile
).
This module makes a copy of the file in memory beforehand so that you can use the sync API and write API on deno deploy.
Usage
Live samples are in ./example/main.ts and https://deploy-sqlite.deno.dev/.
With this module, SQLite works on deno deploy.
import { serve } from "https://deno.land/std@0.144.0/http/mod.ts";
import { DB } from "https://deno.land/x/sqlite@v3.4.0/mod.ts";
import { prepareLocalFile, prepareVirtualFile } from "../mod.ts";
await prepareLocalFile("./db.sqlite");
prepareVirtualFile("./db.sqlite-journal");
// read db
const db = new DB("./db.sqlite", { mode: "read" });
// very simple server
serve(() => Response.json(db.query("SELECT * FROM people")));
Support status
- Deno.FsFile#read(p: Uint8Array): Promise<number | null>
- Deno.FsFile#readSync(p: Uint8Array): number | null
- Deno.FsFile#write(p: Uint8Array): Promise
- Deno.FsFile#writeSync(p: Uint8Array): number
- Deno.FsFile#seek(offset: number, whence: Deno.SeekMode): Promise
- Deno.FsFile#seekSync(offset: number, whence: Deno.SeekMode): number
- Deno.FsFile#stat(): Promise<Deno.FileInfo>
- Deno.FsFile#statSync(): Deno.FileInfo
- Deno.FsFile#truncate(len?: number | undefined): Promise
- Deno.FsFile#truncateSync(len?: number | undefined): void
- Deno.FsFile#close()
- Deno.FsFile#readable
- Deno.FsFile#writable
- Deno.FsFile#rid
- Deno.read(rid: number, buffer: Uint8Array): Promise<number | null>
- Deno.readSync(rid: number, buffer: Uint8Array): number | null
- Deno.write(rid: number, data: Uint8Array): Promise
- Deno.writeSync(rid: number, data: Uint8Array): number
- Deno.seek(rid: number, offset: number, whence: Deno.SeekMode): Promise
- Deno.seekSync(rid: number, offset: number, whence: Deno.SeekMode): number
- Deno.fstat(rid: number): Promise<Deno.FileInfo>
- Deno.fstatSync(rid: number): Deno.FileInfo
- Deno.ftruncate(rid: number, len?: number | undefined): Promise
- Deno.ftruncateSync(rid: number, len?: number | undefined): void
- Deno.close(rid: number): void
- Deno.open(path: string | URL, options?: Deno.OpenOptions | undefined): Promise<Deno.FsFile>
- Deno.openSync(path: string | URL, options?: Deno.OpenOptions | undefined): Deno.FsFile
- Deno.readFile(path: string | URL, options?: Deno.ReadFileOptions | undefined): Promise
- Deno.readFileSync(path: string | URL): Uint8Array
- Deno.readTextFile(path: string | URL, options?: Deno.ReadFileOptions | undefined): Promise
- Deno.readTextFileSync(path: string | URL): string
- Deno.writeFile(path: string | URL, data: Uint8Array, options?: Deno.WriteFileOptions | undefined): Promise
- Deno.writeFileSync(path: string | URL, data: Uint8Array, options?: Deno.WriteFileOptions | undefined): void
- Deno.writeTextFile(path: string | URL, data: string, options?: Deno.WriteFileOptions | undefined): Promise
- Deno.writeTextFileSync(path: string | URL, data: string, options?: Deno.WriteFileOptions | undefined): void
- Deno.fdatasyncSync(rid: number): void
- Deno.fsync(rid: number): Promise
- Deno.fdatasyncSync(rid: number): void
- Deno.fdatasync(rid: number): Promise
- Deno.flock(rid: number, exclusive?: boolean | undefined): Promise
- Deno.flockSync(rid: number, exclusive?: boolean | undefined): void
- Deno.funlock(rid: number): Promise
- Deno.funlockSync(rid: number): void
- Deno.stat(path: string | URL): Promise<Deno.FileInfo>
- Deno.statSync(path: string | URL): Deno.FileInfo
- Deno.truncate(name: string, len?: number | undefined): Promise
- Deno.truncateSync(name: string, len?: number | undefined): void