Created
January 30, 2020 16:44
-
-
Save lpnam0201/e0ca6a19c123b93a439714c8f4f7f6b0 to your computer and use it in GitHub Desktop.
FileSystemDirectoryReader.readEntries() only returns 100 entries a time, must be called repeatedly to enumerate all entries.
This file contains 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
function readEntriesAsync(reader) { | |
return new Promise((resolve, reject) => { | |
reader.readEntries(entries => { | |
resolve(entries); | |
}, error => reject(error)); | |
}) | |
} | |
async function enumerateDirectoryWithManyFiles(directoryEntry) { | |
let reader = directoryEntry.createReader(); | |
let resultEntries = []; | |
let read = async function() { | |
let entries = await readEntriesAsync(reader); | |
if (entries.length > 0) { | |
resultEntries = resultEntries.concat(entries); | |
await read(); | |
} | |
} | |
await read(); | |
return resultEntries; | |
} | |
// Run in chrome extension's background page's console | |
chrome.runtime.getPackageDirectoryEntry(async rootEntry => { | |
let entries = await enumerateDirectoryWithManyFiles(rootEntry); | |
console.log(entries); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment