native-file-system-adapter
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "native-file-system-adapter", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Native File System API", | ||
@@ -5,0 +5,0 @@ "main": "src/es6.js", |
@@ -5,3 +5,3 @@ # Native File System adapter (ponyfill) | ||
This is file system that follows [native-file-system](https://wicg.github.io/native-file-system/) specification. Thanks to it we can have a unified way of handling data in all browser and even in NodeJS in a more secure way. | ||
This is file system that follows [native-file-system](https://wicg.github.io/native-file-system/) specification. Thanks to it we can have a unified way of handling data in all browser and even in NodeJS & Deno in a more secure way. | ||
@@ -18,3 +18,4 @@ At a high level what we're providing is several bits: | ||
* `node`: Interact with filesystem using nodes `fs` | ||
* `node`: Interact with filesystem using NodeJS `fs` | ||
* `deno`: Interact with filesystem using Deno | ||
* `native`: Stores files the `Native Sandboxed` file file system storage | ||
@@ -68,2 +69,5 @@ * `Sandbox`: Stores files into the Blinks `Sandboxed FileSystem` API. | ||
// Deno only variant: | ||
handle = await getOriginPrivateDirectory(import('native-file-system-adapter/src/adapters/memory.js')) | ||
handle = await getOriginPrivateDirectory(import('native-file-system-adapter/src/adapters/deno.js'), './starting-path') | ||
@@ -70,0 +74,0 @@ |
import FileSystemHandle from './FileSystemHandle.js' | ||
import FileSystemFileHandle from './FileSystemFileHandle.js' | ||
const kAdapter = Symbol('adapter') | ||
class FileSystemDirectoryHandle extends FileSystemHandle { | ||
/** @type {FileSystemDirectoryHandle} */ | ||
#adapter | ||
[kAdapter] | ||
constructor (adapter) { | ||
super(adapter) | ||
this.#adapter = adapter | ||
this[kAdapter] = adapter | ||
} | ||
@@ -22,3 +24,3 @@ | ||
if (name === '.' || name === '..' || name.includes('/')) throw new TypeError(`Name contains invalid characters.`) | ||
return new FileSystemDirectoryHandle(await this.#adapter.getDirectoryHandle(name, options)) | ||
return new FileSystemDirectoryHandle(await this[kAdapter].getDirectoryHandle(name, options)) | ||
} | ||
@@ -28,3 +30,3 @@ | ||
async * entries () { | ||
for await (const [_, entry] of this.#adapter.entries()) | ||
for await (const [_, entry] of this[kAdapter].entries()) | ||
yield [entry.name, entry.kind === 'file' ? new FileSystemFileHandle(entry) : new FileSystemDirectoryHandle(entry)] | ||
@@ -36,3 +38,3 @@ } | ||
console.warn('deprecated, use .entries() instead') | ||
for await (let entry of this.#adapter.entries()) | ||
for await (let entry of this[kAdapter].entries()) | ||
yield entry.kind === 'file' ? new FileSystemFileHandle(entry) : new FileSystemDirectoryHandle(entry) | ||
@@ -47,6 +49,7 @@ } | ||
*/ | ||
async getFileHandle (name, options) { | ||
async getFileHandle (name, options = {}) { | ||
if (name === '') throw new TypeError(`Name can't be an empty string.`) | ||
if (name === '.' || name === '..' || name.includes('/')) throw new TypeError(`Name contains invalid characters.`) | ||
return new FileSystemFileHandle(await this.#adapter.getFileHandle(name, options)) | ||
options.create = !!options.create | ||
return new FileSystemFileHandle(await this[kAdapter].getFileHandle(name, options)) | ||
} | ||
@@ -63,3 +66,3 @@ | ||
options.recursive = !!options.recursive // cuz node's fs.rm require boolean | ||
return this.#adapter.removeEntry(name, options) | ||
return this[kAdapter].removeEntry(name, options) | ||
} | ||
@@ -66,0 +69,0 @@ |
import FileSystemHandle from './FileSystemHandle.js' | ||
import FileSystemWritableFileStream from './FileSystemWritableFileStream.js' | ||
const kAdapter = Symbol('adapter') | ||
class FileSystemFileHandle extends FileSystemHandle { | ||
/** @type {FileSystemFileHandle} */ | ||
#adapter | ||
[kAdapter] | ||
constructor (adapter) { | ||
super(adapter) | ||
this.#adapter = adapter | ||
this[kAdapter] = adapter | ||
} | ||
@@ -20,3 +22,3 @@ | ||
return new FileSystemWritableFileStream( | ||
await this.#adapter.createWritable(options) | ||
await this[kAdapter].createWritable(options) | ||
) | ||
@@ -29,3 +31,3 @@ } | ||
getFile () { | ||
return Promise.resolve(this.#adapter.getFile()) | ||
return Promise.resolve(this[kAdapter].getFile()) | ||
} | ||
@@ -32,0 +34,0 @@ } |
@@ -1,6 +0,6 @@ | ||
const wm = new WeakMap() | ||
const kAdapter = Symbol('adapter') | ||
class FileSystemHandle { | ||
/** @type {FileSystemHandle} */ | ||
#adapter | ||
[kAdapter] | ||
@@ -16,3 +16,3 @@ /** @type {string} */ | ||
this.name = adapter.name | ||
this.#adapter = adapter | ||
this[kAdapter] = adapter | ||
} | ||
@@ -22,5 +22,5 @@ | ||
if (options.readable) return 'granted' | ||
const handle = this.#adapter | ||
const handle = this[kAdapter] | ||
return handle.queryPermission ? | ||
handle.queryPermission(options) : | ||
await handle.queryPermission(options) : | ||
handle.writable | ||
@@ -33,3 +33,3 @@ ? 'granted' | ||
if (options.readable) return 'granted' | ||
const handle = this.#adapter | ||
const handle = this[kAdapter] | ||
return handle.writable ? 'granted' : 'denied' | ||
@@ -45,3 +45,3 @@ } | ||
async remove (options = {}) { | ||
this.#adapter.remove(options) | ||
await this[kAdapter].remove(options) | ||
} | ||
@@ -55,3 +55,3 @@ | ||
if (this.kind !== other.kind) return false | ||
return this.#adapter.isSameEntry(other.#adapter) | ||
return this[kAdapter].isSameEntry(other[kAdapter]) | ||
} | ||
@@ -58,0 +58,0 @@ } |
@@ -17,3 +17,3 @@ /* global DataTransfer, DataTransferItem */ | ||
]) | ||
console.log('jo') | ||
return entry.isFile | ||
@@ -20,0 +20,0 @@ ? new FileSystemFileHandle(new FileHandle(entry, false)) |
@@ -37,37 +37,1 @@ import * as fs from '../src/es6.js' | ||
start() | ||
// globalThis.fs = fs | ||
// async function init () { | ||
// const drivers = await Promise.allSettled([ | ||
// getOriginPrivateDirectory(), | ||
// getOriginPrivateDirectory(import('../src/adapters/sandbox.js')), | ||
// getOriginPrivateDirectory(import('../src/adapters/memory.js')), | ||
// getOriginPrivateDirectory(import('../src/adapters/indexeddb.js')), | ||
// getOriginPrivateDirectory(import('../src/adapters/cache.js')) | ||
// ]) | ||
// let j = 0 | ||
// for (const driver of drivers) { | ||
// j++ | ||
// if (driver.status === 'rejected') continue | ||
// const root = driver.value | ||
// await cleanupSandboxedFileSystem(root) | ||
// const total = performance.now() | ||
// for (var i = 0; i < tests.length; i++) { | ||
// const test = tests[i] | ||
// await cleanupSandboxedFileSystem(root) | ||
// const t = performance.now() | ||
// await test.fn(root).then(() => { | ||
// const time = (performance.now() - t).toFixed(3) | ||
// tBody.rows[i].cells[j].innerText = time + 'ms' | ||
// }, err => { | ||
// console.error(err) | ||
// tBody.rows[i].cells[j].innerText = '❌' | ||
// tBody.rows[i].cells[j].title = err.message | ||
// }) | ||
// } | ||
// table.tFoot.rows[0].cells[j].innerText = (performance.now() - total).toFixed(3) | ||
// } | ||
// } | ||
// init().catch(console.error) |
@@ -17,2 +17,7 @@ import * as fs from '../src/es6.js' | ||
if (!globalThis.WritableStream) { | ||
const m = await import('https://cdn.jsdelivr.net/npm/web-streams-polyfill@3/dist/ponyfill.es2018.mjs') | ||
globalThis.ReadableStream = m.ReadableStream | ||
} | ||
/** @type {typeof window.Blob} */ | ||
@@ -19,0 +24,0 @@ const Blob = globalThis.Blob || await import('fetch-blob').then(m => m.Blob) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
130513
33
3304
176