Package

purescript-web-file-directory-entries

Repository
xc-jp/purescript-web-file-directory-entries
License
BSD-3-Clause
Uploaded by
jamesdbrock
Published on
2021-02-15T09:25:53Z

Pursuit

Type definitions and implementation for the File and Directory Entries API WICG Draft Report. This API is not a standard, and will probably never be a standard.

This library is incomplete. It currently contains the useful read-only portion of the File and Directory Entries API which we needed to implement drag-and-drop file upload on a web page, where the “file” being uploaded can be multiple files or an entire directory tree.

There is another portion of the File and Directory Entries API concerned with writing to a file system, and that portion we have not yet implemented, and we probably never will.

Pull requests welcome!

References

Usage Example

import React.Basic.Events (EventHandler)
import React.Basic.DOM.Events (capture, dataTransfer)
import Data.Filterable (partitionMap)
import Effect.Aff (launchAff_)
import Web.FileAndDirectoryEntries (getEntries, readDirectory)

onDropHandler :: EventHandler
onDropHandler = capture dataTransfer $ maybe (pure unit) $ \dataTrans -> do
  let { left: files, right: dirs } = partitionMap identity $ getEntries dataTrans
  launchAff_ do
    for dirs $ \dir -> do
      { left: subfiles, right: subdirs } <- partitionMap identity <$> readDirectory dir
  ...