Package

purescript-js-fileio

Repository
newlandsvalley/purescript-js-fileio
License
MIT
Uploaded by
newlandsvalley
Published on
2022-05-06T20:15:28Z

Provide the facility for browser-based applications to read and write files to and from the local file system in a simple manner. PureScript wrappers are supplied for the JavaScript functions readAsText, readAsBinaryString and URL.createObjectURL (with a text payload). The exported functions are:

  • loadTextFile
  • loadBinaryFileAsText
  • saveTextFile

Note that readAsBinaryString is effectively deprecated in javascript. As far as I can tell, it was originally dropped from the W3C File API specification but later reappeared because of backward compatibility. The spec says that readAsArrayBuffer is preferred.

Because of this, I am a little leery of publishing the project, but nevertheless am doing so because I find it so useful when implementing load and save buttons.

If, alternatively, you intend to make use of Halogen's onFileUpload event, then this treats files in terms of the Web File API. This approach requires the use of a subsequent loadend callback which I think means that coroutines must be used if you need to get hold of the file's contents.

To build

spago build

or

bower install
pulp build

To build the Halogen example

npm run halogen-example

And then navigate to the halogen_example/dist directory.

Modules
JS.FileIO
Dependencies