Sunday 15 August 2010

html5 - Progressively read binary file in JavaScript -


Using chrome, I am trying to read and process a large (& gt; 4GB) binary file on my local disk.

This file contains a sequence of frames containing a 1-byte type identifier, a 2-byte frame length, 8-byte time stamp, and then some binary data that is format based on format . The contents of these frames will be stored, and I want to use HTML5 + Javascript to create graphics and display other metrics in the form of real-time playback based on the content of this file.

Anyone have any ideas?

Basically, files are blops and blobs are one piece method, which we capture small portions of large files Can use for

I wrote to filter large log files last week, but this pattern shows that you have loop sub-

  • file is a file object
  • The Funnelline filter is a function that accepts a line of file and gives it the right to keep it
    1. li>
    2. fnComplete is a callback where an aggregated lines form an array Is passed

      Here is the code I used:

        function fileF Ilter (file, FnLineFilter, fnComplete) {var bPos = 0, mx = file.size, BUFF_SIZE = 262144, i = 0, collection = [], lineCount = 0; Var d1 = + new date; Var balance = ""; Grab function Next Chunk () {var myBlob = file.slice (BUFF_SIZE * i, (BUFF_SIZE * i) + BUFF_SIZE, file.type); I ++; Var fr = New FileReader (); Fr.onload = function (e) {// run line filter: var str = remainder + e.target.result, o = str, r = str.split (/ \ r? \ N /); Balance = r.slice (-1) [0]; R.pop (); LineCount + = R. Lamps; Var Rage = R.map (Funnel Filter). Filter (boolean); If (rez.length) {[] .push.apply (collection, rays); } / * End if * / if ((BUFF_SIZE * i)> MX) {fnComplete (collection); Console.log ("filtered" + file.name + "+ + (+ new date () - d1) +" ms "); } / * End if ((BUFF_SIZE * i)> Mx) * / else {setTimeout (grabler, fickle, 0); }}; Fr.readAsText (myBlob, myBlob.type); } / * End grab Next Chunk () * / grabber (Chunk); } / * End fileFilter () * /   

      Obviously, you can get rid of searching the line, and only hold pure categories instead; I was not sure what type of data you need to dig, and the important thing is that slice mechanics, which are well displayed with text-centric code.

  • No comments:

    Post a Comment