Skip to content

Commit cbd8dcd

Browse files
committed
Degraded private field to Symbol
1 parent ac1693c commit cbd8dcd

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "native-file-system-adapter",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Native File System API",
55
"main": "src/es6.js",
66
"module": "./src/es6.js",

src/FileSystemDirectoryHandle.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import FileSystemHandle from './FileSystemHandle.js'
22
import FileSystemFileHandle from './FileSystemFileHandle.js'
33

4+
const kAdapter = Symbol('adapter')
5+
46
class FileSystemDirectoryHandle extends FileSystemHandle {
57
/** @type {FileSystemDirectoryHandle} */
6-
#adapter
8+
[kAdapter]
79

810
constructor (adapter) {
911
super(adapter)
10-
this.#adapter = adapter
12+
this[kAdapter] = adapter
1113
}
1214

1315
/**
@@ -19,19 +21,19 @@ class FileSystemDirectoryHandle extends FileSystemHandle {
1921
async getDirectoryHandle (name, options = {}) {
2022
if (name === '') throw new TypeError(`Name can't be an empty string.`)
2123
if (name === '.' || name === '..' || name.includes('/')) throw new TypeError(`Name contains invalid characters.`)
22-
return new FileSystemDirectoryHandle(await this.#adapter.getDirectoryHandle(name, options))
24+
return new FileSystemDirectoryHandle(await this[kAdapter].getDirectoryHandle(name, options))
2325
}
2426

2527
/** @returns {AsyncGenerator<[string, FileSystemHandle], void, unknown>} */
2628
async * entries () {
27-
for await (const [_, entry] of this.#adapter.entries())
29+
for await (const [_, entry] of this[kAdapter].entries())
2830
yield [entry.name, entry.kind === 'file' ? new FileSystemFileHandle(entry) : new FileSystemDirectoryHandle(entry)]
2931
}
3032

3133
/** @deprecated use .entries() instead */
3234
async * getEntries() {
3335
console.warn('deprecated, use .entries() instead')
34-
for await (let entry of this.#adapter.entries())
36+
for await (let entry of this[kAdapter].entries())
3537
yield entry.kind === 'file' ? new FileSystemFileHandle(entry) : new FileSystemDirectoryHandle(entry)
3638
}
3739

@@ -45,7 +47,7 @@ class FileSystemDirectoryHandle extends FileSystemHandle {
4547
if (name === '') throw new TypeError(`Name can't be an empty string.`)
4648
if (name === '.' || name === '..' || name.includes('/')) throw new TypeError(`Name contains invalid characters.`)
4749
options.create = !!options.create
48-
return new FileSystemFileHandle(await this.#adapter.getFileHandle(name, options))
50+
return new FileSystemFileHandle(await this[kAdapter].getFileHandle(name, options))
4951
}
5052

5153
/**
@@ -57,7 +59,7 @@ class FileSystemDirectoryHandle extends FileSystemHandle {
5759
if (name === '') throw new TypeError(`Name can't be an empty string.`)
5860
if (name === '.' || name === '..' || name.includes('/')) throw new TypeError(`Name contains invalid characters.`)
5961
options.recursive = !!options.recursive // cuz node's fs.rm require boolean
60-
return this.#adapter.removeEntry(name, options)
62+
return this[kAdapter].removeEntry(name, options)
6163
}
6264

6365
[Symbol.asyncIterator]() {

src/FileSystemFileHandle.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import FileSystemHandle from './FileSystemHandle.js'
22
import FileSystemWritableFileStream from './FileSystemWritableFileStream.js'
33

4+
const kAdapter = Symbol('adapter')
5+
46
class FileSystemFileHandle extends FileSystemHandle {
57
/** @type {FileSystemFileHandle} */
6-
#adapter
8+
[kAdapter]
79

810
constructor (adapter) {
911
super(adapter)
10-
this.#adapter = adapter
12+
this[kAdapter] = adapter
1113
}
1214

1315
/**
@@ -17,15 +19,15 @@ class FileSystemFileHandle extends FileSystemHandle {
1719
*/
1820
async createWritable (options = {}) {
1921
return new FileSystemWritableFileStream(
20-
await this.#adapter.createWritable(options)
22+
await this[kAdapter].createWritable(options)
2123
)
2224
}
2325

2426
/**
2527
* @returns {Promise<File>}
2628
*/
2729
getFile () {
28-
return Promise.resolve(this.#adapter.getFile())
30+
return Promise.resolve(this[kAdapter].getFile())
2931
}
3032
}
3133

src/FileSystemHandle.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const wm = new WeakMap()
1+
const kAdapter = Symbol('adapter')
22

33
class FileSystemHandle {
44
/** @type {FileSystemHandle} */
5-
#adapter
5+
[kAdapter]
66

77
/** @type {string} */
88
name
@@ -13,12 +13,12 @@ class FileSystemHandle {
1313
constructor (adapter) {
1414
this.kind = adapter.kind
1515
this.name = adapter.name
16-
this.#adapter = adapter
16+
this[kAdapter] = adapter
1717
}
1818

1919
async queryPermission (options = {}) {
2020
if (options.readable) return 'granted'
21-
const handle = this.#adapter
21+
const handle = this[kAdapter]
2222
return handle.queryPermission ?
2323
await handle.queryPermission(options) :
2424
handle.writable
@@ -28,7 +28,7 @@ class FileSystemHandle {
2828

2929
async requestPermission (options = {}) {
3030
if (options.readable) return 'granted'
31-
const handle = this.#adapter
31+
const handle = this[kAdapter]
3232
return handle.writable ? 'granted' : 'denied'
3333
}
3434

@@ -39,7 +39,7 @@ class FileSystemHandle {
3939
* @param {boolean} [options.recursive=false]
4040
*/
4141
async remove (options = {}) {
42-
await this.#adapter.remove(options)
42+
await this[kAdapter].remove(options)
4343
}
4444

4545
/**
@@ -48,7 +48,7 @@ class FileSystemHandle {
4848
async isSameEntry (other) {
4949
if (this === other) return true
5050
if (this.kind !== other.kind) return false
51-
return this.#adapter.isSameEntry(other.#adapter)
51+
return this[kAdapter].isSameEntry(other[kAdapter])
5252
}
5353
}
5454

src/getOriginPrivateDirectory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (globalThis.DataTransferItem && !DataTransferItem.prototype.getAsFileSystemHa
1414
import('./FileSystemDirectoryHandle.js'),
1515
import('./FileSystemFileHandle.js')
1616
])
17-
console.log('jo')
17+
1818
return entry.isFile
1919
? new FileSystemFileHandle(new FileHandle(entry, false))
2020
: new FileSystemDirectoryHandle(new FolderHandle(entry, false))

test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import {
1414
capture
1515
} from './util.js'
1616

17+
if (!globalThis.WritableStream) {
18+
const m = await import('https://cdn.jsdelivr.net/npm/web-streams-polyfill@3/dist/ponyfill.es2018.mjs')
19+
globalThis.ReadableStream = m.ReadableStream
20+
}
21+
1722
/** @type {typeof window.Blob} */
1823
const Blob = globalThis.Blob || await import('fetch-blob').then(m => m.Blob)
1924

0 commit comments

Comments
 (0)