Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FileSystemDirectoryReader.readEntries() only returns 100 entries a time, must be called repeatedly to enumerate all entries.
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