Created
July 5, 2020 06:53
-
-
Save xsolon/5d1a359b4bcf1beb83b08916101d5b26 to your computer and use it in GitHub Desktop.
Native Api Samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Api from 'spexplorerjs'; | |
import 'nativefs'; | |
console.clear(); | |
// @ts-ignore | |
//var xml = xmlEditor.getValue(); | |
var ns: Api.Ispexplorerjs = window['spexplorerjs'] | |
var logger = new ns.modules.logger('test'); | |
logger.log('Starting...'); | |
var utils = new ns.modules.utils(); | |
//import 'node_modules/@types/nativefs/nativefs'; | |
var d: ChooseFileSystemEntriesOptions = { d: 1 }; | |
var readDirectory = async () => { | |
//@ts-ignore | |
const opts: ChooseFileSystemEntriesOptions = { type: 'open-directory' }; | |
//@ts-ignore | |
const handle: FileSystemDirectoryHandle = await window.chooseFileSystemEntries(opts); | |
handle.getDirectory("sub", { create: true }).then((h => { | |
debugger; | |
})); | |
var updateFile = async (file: FileSystemFileHandle, content: string) => { | |
const writable = await file.createWritable();// Create a FileSystemWritableFileStream to write to. | |
await writable.write(content);// Write the contents of the file to the stream. | |
await writable.close();// Close the file and write the contents to disk. | |
}; | |
const entries = await handle.getEntries(); | |
var file: FileSystemFileHandle; | |
for await (file of entries) { | |
if (file.isFile) { | |
debugger; | |
await updateFile(file, 'blah 3'); | |
console.log({ | |
file: file.name, content: (await (await file.getFile()).text()) | |
}); | |
} | |
} | |
}; | |
readDirectory(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment