newlandsvalley / purescript-js-fileio

Wrapped JavaScript functions for reading and writing simple files

Repository from Github https://github.comnewlandsvalley/purescript-js-fileioRepository from Github https://github.comnewlandsvalley/purescript-js-fileio

purescript-js-fileio

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

To build the Halogen example

npm run example

And then navigate to the halogen_example/dist directory.

About

Wrapped JavaScript functions for reading and writing simple files

License:MIT License


Languages

Language:PureScript 67.4%Language:JavaScript 26.3%Language:Dhall 6.3%