import { IWebkitFileSystem } from "./IWebkitFileSystem" ; import { FileSystemDirectoryReaders } from "./FileSystemDirectoryReaders" ; export namespace FileSystemEntries { import IWebkitFileSystemEntry = IWebkitFileSystem . IWebkitFileSystemEntry ; import IWebkitFileSystemFileEntry = IWebkitFileSystem . IWebkitFileSystemFileEntry ; import IWebkitFileSystemDirectoryEntry = IWebkitFileSystem . IWebkitFileSystemDirectoryEntry ; export function isFile ( entry ) { return entry . isFile ; } export function isDirectory ( entry ) { return entry . isDirectory ; } export async function recurseDataTransferItems ( items ) { return recurseFileSystemEntries ( items . map ( item => item . webkitGetAsEntry ( ) ) ) ; } export async function recurseFileSystemEntries ( entries ) { const result = [ ] ; for ( const entry of entries ) { if ( entry . isFile ) { result . push ( entry ) ; } else if ( FileSystemEntries . isDirectory ( entry ) ) { const reader = entry . createReader ( ) ; const asyncReader = FileSystemDirectoryReaders . toAsync ( reader ) ; while ( true ) { const dirEntries = await asyncReader . readEntries ( ) ; if ( dirEntries . length === 0 ) { break ; } const recursedEntries = await recurseFileSystemEntries ( dirEntries ) ; result . push ( ... recursedEntries ) ; } } } return result ; } }