KO
|
EN
gitlite — search
Search
#javascript
#python
#hacktoberfest
#react
#ai
#typescript
#llm
#go
#golang
#android
#machine-learning
#rust
#deep-learning
#linux
deno-using
★ 11
Open GitHub ↗
python-style with statements for deno
Download README (.md)
Explore Similar Repositories
TrainTimer
:
最寄り駅の電車が何分後に来るか表示します。
sspanel-autocheckin
:
适用于sspanel魔改版的自动签到
Spark2CassandraBulkLoad
:
Spark Library for Bulk Loading into Cassandra
ses-smtpd-proxy
:
Simple SMTP to SES Mail Proxy
wimble
:
Wimble – Wallet reinvented for Grin.
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
deno-using
?
Download (.md)
# deno-using A python-style with statement for deno. Comes with some `Using` types, e.g. `Open`, `ChDir`, `TempDir`, and `Timeout`. ## Example: ```ts import { using, Open } from "htps://deno.land/x/using/mod.ts"; const enc = new TextEncoder(); const dec = new TextDecoder(); await using(new Open("file", "w"), async (f: Deno.File) => { const data = enc.encode("Hello world!\n"); await f.write(data); }); await using(new Open("file", "r"), async (f: Deno.File) => { const data = new Uint8Array(20); await f.read(data); const text = dec.decode(data); console.log(text); }); ``` There is also a corresponding sync version `UsingSync`. ## Custom types You can define your own `Using` types by creating a class which implements `Using`: ```ts export class Open implements Using<Deno.File> { constructor(filename: string, mode?: Deno.OpenMode) { this.filename = filename; this.mode = mode; } public async _aenter() { this.file = await Deno.open(this.filename, this.mode); return this.file; } public async _aexit(e) { this.file.close(); } private file: Deno.File; private filename: string; private mode: Deno.OpenMode; } ```