- Notifications
You must be signed in to change notification settings - Fork12
HTML5 FileAPI `FileReader` for Node.JS.
License
node-file-api/FileReader
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
HTML5 FileAPIFileReader
for Node.JS(could potentially be modified to work with older browsers as well).
Seehttps://github.com/node-file-api/file-api andhttps://developer.mozilla.org/en-US/docs/Web/API/FileReader
'use strict';varFileReader=require('filereader'),fileReader=newFileReader();fileReader.setNodeChunkedEncoding(true||false);fileReader.readAsDataURL(newFile('./files/my-file.txt'));// non-standard alias of `addEventListener` listening to non-standard `data` eventfileReader.on('data',function(data){console.log("chunkSize:",data.length);});// `onload` as listenerfileReader.addEventListener('load',function(ev){console.log("dataUrlSize:",ev.target.result.length);});// `onloadend` as propertyfileReader.onloadend',function(){console.log("Success");});
Implemented API
.readAsArrayBuffer(<File>)
.readAsBinaryString(<File>)
.readAsDataURL(<File>)
.readAsText(<File>)
.addEventListener(eventname, callback)
.removeEventListener(callback)
.dispatchEvent(eventname)
.EMPTY = 0
.LOADING = 1
.DONE = 2
.error = undefined
.readyState = self.EMPTY
.result = undefined
Events
- start
- progress
- error
- load
- end
- abort
- data // non-standard
Event Payload
end
{ target:{nodeBufferResult:<Buffer> // non-standard , result:<Buffer|Binary|Text|DataURL>}}
progress
// fs.stat will probably complete before this// but possibly it will not, hence the check{lengthComputable:(!isNaN(file.size)) ?true :false,loaded:buffers.dataLength,total:file.size}
Non-W3C API
.on(eventname, callback)
.nodeChunkedEncoding = false
.setNodeChunkedEncoding(<Boolean>)
FileReader.setNodeChunkedEncoding() is anon-standard method which hints that theFileReader
should chunk if possible
I.E. The file will be sent with the headerTransfer-Encoding: chunked
The default isfalse
since many webservers do not correctly implement the standard correctly,and hence do not expect or acceptTransfer-Encoding: chunked
from clients.
FileReader.on is anon-standard alias ofaddEventListener
EventTarget.target.nodeBufferResult is anon-standard property which is aNode.Buffer
instance of the data.
FileReader.on('data', fn) is anon-standard event which passes aNode.Buffer
chunk each time theprogress
event is fired.
About
HTML5 FileAPI `FileReader` for Node.JS.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.