-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use Deno FileDescriptor for CSV export
- Loading branch information
1 parent
c5db1db
commit 8f1c885
Showing
2 changed files
with
63 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,47 @@ | ||
import { join } from "@/lib/path/index.ts"; | ||
|
||
let tmpDir: string; | ||
|
||
/** | ||
* Create a new temporary directory if it doesn't exist yet. | ||
* Otherwise, return the existing one from the tmpDir variable. | ||
*/ | ||
export function getTmpDir(): string { | ||
if (!tmpDir) { | ||
tmpDir = Deno.makeTempDirSync(); | ||
const parts = Deno.makeTempDirSync().split("/"); | ||
parts.pop(); | ||
tmpDir = "/" + join(...parts); | ||
} | ||
|
||
return tmpDir; | ||
} | ||
|
||
export type OpenFileOptions = Deno.OpenOptions; | ||
export type OpenFileDescriptor = Deno.FsFile; | ||
|
||
/** | ||
* Create and open a file for reading and writing. | ||
* | ||
* @example | ||
* const fd = await open("example.txt", { read: true, write: true }); | ||
* fd.close(); | ||
* | ||
* @example | ||
* const df = await open("example.txt", { write: true, append: true }); | ||
* await fd.write(new TextEncoder().encode("Hello, World!")); | ||
* await fd.write(new TextEncoder().encode("Hello, World!")); | ||
* fd.close(); | ||
* | ||
* @param filepath | ||
* @param options | ||
* @returns | ||
*/ | ||
export function open( | ||
filepath: string, | ||
options: OpenFileOptions = { read: true }, | ||
): Promise<OpenFileDescriptor> { | ||
return Deno.open(filepath, { | ||
...options, | ||
create: true, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters