- Notifications
You must be signed in to change notification settings - Fork15
A simple, high-performance, and comprehensive file system API running in the browser, built on OPFS. 在浏览器中运行的简单、高性能、完备的文件系统 API,基于 OPFS 构建。
License
hughfenghen/opfs-tools
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
EN: A simple, high-performance, and comprehensive file system API running in the browser, built onOPFS.
CN: 在浏览器中运行的简单、高性能、完备的文件系统 API,基于OPFS 构建。
import{file,dir,write}from'opfs-tools';// --------- Create / Write ---------awaitdir('/test-dir').create();// create a directoryawaitwrite('/dir/file.txt','');// empty fileawaitwrite('/dir/fetch-file',(awaitfetch('//example.com')).body);// inputFile from the input element picked by the userawaitwrite('/dir/input-file',inputFile.stream());// For incremental file writes, please refer to the API documentation.constwriter=awaitfile('/dir/file').createWriter();// --------- Read ---------awaitfile('/dir/file.txt').text();awaitfile('/dir/input-file').arrayBuffer();awaitfile('/dir/input-file').stream();// If you want to read file fragments, please refer to the API documentation.constreader=awaitfile('/dir/input-file').createReader();awaitdir('/test-dir').children();// --------- Remove ---------awaitdir('/test-dir').remove();awaitfile('/dir/file.txt').remove();// --------- copyTo / moveTo ---------awaitfile('/dir/file').copyTo(file('/dir/file copy1'));awaitdir('/dir').moveTo(dir('/.Trash'));// --------- import/export file -----------const[impHandle]=awaitwindow.showOpenFilePicker();write('/import-file',(awaitimpHandle.getFile()).stream());constexpHandle=awaitwindow.showSaveFilePicker({suggestedName:`opfs-export-file`,});(awaitfile('/export-file').stream()).pipeTo(awaitexpHandle.createWritable());// --------- upload -------------constformData=newFormData();formData.append('file',awaitfile('/upload-file').getOriginFile());awaitfetch('/upload',{method:'post',headers:{'Content-Type':'multipart/form-data'},body:formData,});
opfs-finder
使用 AI + OPFS 在浏览器中实现 MacOS Finder。Implement MacOS Finder in the browser using AI + OPFS.
opfs-tools-explorer
Manage OPFS assets in your web site, supporting file creation, copying, and moving features, providing a user-friendly interactive experience.
- Basic operations
- file
- remove
- exists
- dir
- create
- remove
- exists
- children
- file
- Reading files
- getSize
- text
- stream
- arrayBuffer
- Random reading
- reader = file.createReader
- reader.read(bufLen, { at }
- reader.close
- Writing files
- write(dest: string, input: string)
- write(dest: string, input: ArrayBuffer | ArrayBufferView)
- write(dest: string, input: ReadableStream)
- Random writing
- writer = file.createWriter
- writer.write
- writer.flush
- writer.truncate
- writer.close
About
A simple, high-performance, and comprehensive file system API running in the browser, built on OPFS. 在浏览器中运行的简单、高性能、完备的文件系统 API,基于 OPFS 构建。
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Contributors3
Uh oh!
There was an error while loading.Please reload this page.