Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

HTML5 FileAPI `FileReader` for Node.JS.

License

NotificationsYou must be signed in to change notification settings

node-file-api/FileReader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

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>)

Misc Notes on FileReader

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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp