| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/API/File_System_API | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
: Web Worker .
File System API , , . File System Access API .
File System API . API , , .
. FileSystemHandle , FileSystemFileHandle FileSystemDirectoryHandle .
. window.showOpenFilePicker() window.showDirectoryPicker() . .
.
, ( ). , . File System API . API , ( ).
(Origin Private File System, OPFS) File System API , . OPFS , .
FileSystemWritableFileStream . Blob, String , , ArrayBuffer , . .FileSystemSyncAccessHandle write() . , flush() . ( )FileSystemHandle . . FileSystemHandle FileSystemFileHandle FileSystemDirectoryHandle .
FileSystemFileHandle.
FileSystemDirectoryHandle.
FileSystemSyncAccessHandle. . WebAssembly . , .
FileSystemWritableFileStreamWritableStream , .
Window.showDirectoryPicker().
Window.showOpenFilePicker().
Window.showSaveFilePicker().
DataTransferItem.getAsFileSystemHandle()StorageManager.getDirectory() FileSystemDirectoryHandle . FileSystemDirectoryHandle Promise .
.
async function getFile() {
//
const [fileHandle] = await window.showOpenFilePicker();
const file = await fileHandle.getFile();
return file;
}
, getFile() .
const pickerOpts = {
types: [
{
description: "Images",
accept: {
"image/*": [".png", ".gif", ".jpeg", ".jpg"],
},
},
],
excludeAcceptAllOption: true,
multiple: false,
};
async function getTheFile() {
//
const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
//
const fileData = await fileHandle.getFile();
}
. .
const dirName = "directoryToGetName";
// 'currentDirHandle'
const subDir = currentDirHandle.getDirectoryHandle(dirName, { create: true });
, resolve() .
async function returnPathDirectories(directoryHandle) {
//
const [handle] = await self.showOpenFilePicker();
if (!handle) {
//
return;
}
//
const relativePaths = await directoryHandle.resolve(handle);
if (relativePaths === null) {
//
} else {
// relativePaths
for (const name of relativePaths) {
//
console.log(name);
}
}
}
. FileSystemFileHandle . FileSystemFileHandle.createWritable() .
, Blob , .
async function saveFile() {
//
const newHandle = await window.showSaveFilePicker();
// Blob FileSystemWritableFileStream
const writableStream = await newHandle.createWritable();
//
await writableStream.write(imgBlob);
//
await writableStream.close();
}
write() .
//
writableStream.write(data);
//
writableStream.write({ type: "write", position, data });
//
writableStream.write({ type: "seek", position });
// size
writableStream.write({ type: "truncate", size });
.
ArrayBuffer .onmessage = async (e) => {
//
const message = e.data;
// OPFS
const root = await navigator.storage.getDirectory();
const draftHandle = await root.getFileHandle("draft.txt", { create: true });
//
const accessHandle = await draftHandle.createSyncAccessHandle();
//
const fileSize = accessHandle.getSize();
//
const buffer = new DataView(new ArrayBuffer(fileSize));
const readBuffer = accessHandle.read(buffer, { at: 0 });
//
const encoder = new TextEncoder();
const encodedMessage = encoder.encode(message);
const writeBuffer = accessHandle.write(encodedMessage, { at: readBuffer });
//
accessHandle.flush();
// FileSystemSyncAccessHandle
accessHandle.close();
};
: close(), flush(), getSize(), truncate() . , .
| Specification |
|---|
| File System |
| File System Access |
This page was last modified on 2024 10 31 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |