deno.land / x / deno_file_system_access_api@v1.0.1 / mod.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import {basename, join} from 'https://deno.land/std@0.157.0/path/mod.ts'
let constructorKey = Symbol()
class StorageManager { async getDirectory() { return new FileSystemDirectoryHandle(constructorKey, Deno.cwd()) }}
class FileSystemHandle { #path
constructor(key, path) { if (key !== constructorKey) { throw new TypeError('Illegal invocation') }
this.#path = path }
isSameEntry(entry) { return this.#path === entry.#path }
async queryPermission() { let desc = {name: 'read', path: this.#path} let {state} = await Deno.permissions.query(desc) return state }
async requestPermission() { throw '' }}
class FileSystemFileHandle extends FileSystemHandle { #path
constructor(key, path) { super(key, path)
this.#path = path
Object.defineProperty(this, 'kind', { value: 'file', writable: false, enumerable: true })
Object.defineProperty(this, 'name', { value: basename(this.#path), writable: false, enumerable: true }) }
async getFile() { let [bytes, lstat] = await Promise.all([ Deno.readFile(this.#path), Deno.lstat(this.#path), ])
return new File([bytes], this.name, { lastModified: lstat.mtime.valueOf() }) }
async createWritable() { // TODO: implement proper FileSystemWritableFileStream let opts = {create: true, write: true, truncate: true} let file = await Deno.open(this.#path, opts) return file.writable }
async move() { throw new Error('Not implemented') }}
class FileSystemDirectoryHandle extends FileSystemHandle { #path
constructor(key, path) { super(key, path)
this.#path = path
Object.defineProperty(this, 'kind', { value: 'directory', writable: false, enumerable: true })
Object.defineProperty(this, 'name', { value: basename(this.#path), writable: false, enumerable: true }) }
async *entries() { let entries = Deno.readDir(this.#path) for await (let {name, isFile, isDirectory} of entries) { if (isDirectory) yield [name, await this.getDirectoryHandle(name)] else if (isFile) yield [name, await this.getFileHandle(name)] } }
async getFileHandle(name) { let path = join(this.#path, name) return new FileSystemFileHandle(constructorKey, path) }
async getDirectoryHandle(name) { let path = join(this.#path, name) return new FileSystemDirectoryHandle(constructorKey, path) }
async *keys() { for await (let entry of this.entries()) yield entry[0] }
async removeEntry(name, {recursive = false} = {}) { throw new Error('Not implemented') }
async resolve(possibleDescendant) { throw new Error('Not implemented') }
async *values() { for await (let entry of this.entries()) yield entry[1] }
[Symbol.asyncIterator]() { return this.entries() }}
self.StorageManager = StorageManagerself.FileSystemHandle = FileSystemHandleself.FileSystemFileHandle = FileSystemFileHandleself.FileSystemDirectoryHandle = FileSystemDirectoryHandleself.navigator.storage = new StorageManager()
deno_file_system_access_api

Version Info

Tagged at
a year ago