How to read a huge text file through javascript or jquery? - Stack Overflow

How can I read a huge text file line by line through javascript or jquery?I cant read all and split to

How can I read a huge text file line by line through javascript or jquery? I cant read all and split to an array because it will require lots of memmory. I just want to stream it...

EDIT As a note I am working on a google chrome extension so that solutions with fso ActiveX does not work on this browser. Any other ideas?

How can I read a huge text file line by line through javascript or jquery? I cant read all and split to an array because it will require lots of memmory. I just want to stream it...

EDIT As a note I am working on a google chrome extension so that solutions with fso ActiveX does not work on this browser. Any other ideas?

Share edited Feb 24, 2012 at 8:10 user1141820 asked Feb 23, 2012 at 12:10 user1141820user1141820 991 gold badge3 silver badges9 bronze badges 12
  • 2 Are you sure jquery is the right tool for the job? – Filburt Commented Feb 23, 2012 at 12:13
  • Similar question asked here. stackoverflow./questions/585234/… – Chris Gessler Commented Feb 23, 2012 at 12:15
  • I am writing an extension for chrome. I think it should work in client buy this way it will not force the server. What can be the other language that I can use php? – user1141820 Commented Feb 23, 2012 at 12:16
  • The text file will be either a file that is stored in a web adress or in the client puter.... – user1141820 Commented Feb 23, 2012 at 12:17
  • Better to go for java servlet with file streaming.. – Kiran Commented Feb 23, 2012 at 12:19
 |  Show 7 more ments

4 Answers 4

Reset to default 2

HTML5 finally provides a standard way to interact with local files, via the File API specification. As example of its capabilities, the File API could be used to create a thumbnail preview of images as they're being sent to the server, or allow an app to save a file reference while the user is offline. Additionally, you could use client-side logic to verify an upload's mimetype matches its file extension or restrict the size of an upload.

The spec provides several interfaces for accessing files from a 'local' filesystem: 1.File - an individual file; provides readonly information such as name, file size, mimetype, and a reference to the file handle. 2.FileList - an array-like sequence of File objects. (Think or dragging a directory of files from the desktop). 3.Blob - Allows for slicing a file into byte ranges.

When used in conjunction with the above data structures, the FileReader interface can be used to asynchronously read a file through familiar JavaScript event handling. Thus, it is possible to monitor the progress of a read, catch errors, and determine when a load is plete. In many ways the APIs resemble XMLHttpRequest's event model.

Note: At the time of writing this tutorial, the necessary APIs for working with local files are supported in Chrome 6.0 and Firefox 3.6. As of Firefox 3.6.3, the File.slice() method is not supported.

http://www.html5rocks./en/tutorials/file/dndfiles/

Lazy Text View widget is intended to display text on a web-page. The key feature is that it does not load whole text in the browser memory, but it displays only fragment (frame) of file. This allows to display large, very large, huge texts.

he widget provides user interface for text display and requires server-side data source. You have to implement server-side ponent yourself, it's logic is quite simple. When the widget needs next chunk of text, it queries server (using POST-method) for the next chunk.

http://polyakoff.ucoz/

fs.read(fd, buffer, offset, length, position, [callback])

Read data from the file specified by fd.

buffer is the buffer that the data will be written to.

offset is offset within the buffer where writing will start.

length is an integer specifying the number of bytes to read.

position is an integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.

http://nodejs/docs/v0.4.8/api/fs.html#file_System

TextStream and Scripting.FileSystemObject

; object = ObjectOpen("Scripting.FileSystemObject") ; WIL syntax
; ObjectClose(object)                               ; WIL syntax
;
; TextStream = object.CreateTextFile(filename[, overwrite[, unicode]])      ; Creates a file as a TextStream
; TextStream = object.OpenTextFile(filename[, iomode[, create[, format]]])  ; Opens a file as a TextStream
;
; TextStream.Close                       ; Close a text stream.
;
; TextStream.ReadAll                     ; Read the entire stream into a string.
; TextStream.ReadLine                    ; Read an entire line into a string.
; TextStream.Read (n)                    ; Read a specific number of characters into a string.
; 
; TextStream.Write (string)              ; Write a string to the stream.
; TextStream.WriteLine                   ; Write an end of line to the stream.
; TextStream.WriteLine (string)          ; Write a string and an end of line to the stream.
; TextStream.WriteBlankLines (n)         ; Write a number of blank lines to the stream.
; 
; TextStream.SkipLine                    ; Skip a line.
; TextStream.Skip (n)                    ; Skip a specific number of characters.
; 
; TextStream.Line                        ; Current line number.
; TextStream.Column                      ; Current column number.
; 
; TextStream.AtEndOfLine                 ; Boolean Value. Is the current position at the end of a line?
; TextStream.AtEndOfStream               ; Boolean Value. Is the current position at the end of the stream?
; -------------------------------------------------------------------------------------------------------------------------------

Sample Code:

function ReadFiles()
{
  var fso, f1, ts, s;
  var ForReading = 1;
  fso = new ActiveXObject("Scripting.FileSystemObject");
  f1 = fso.CreateTextFile("c:\\testfile.txt", true);
  // Write a line.
  Response.Write("Writing file <br>");
  f1.WriteLine("Hello World");
  f1.WriteBlankLines(1);
  f1.Close();
  // Read the contents of the file.
  Response.Write("Reading file <br>");
  ts = fso.OpenTextFile("c:\\testfile.txt", ForReading);
  s = ts.ReadLine();
  Response.Write("File contents = '" + s + "'");
  ts.Close();
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745059781a4608893.html

相关推荐

  • How to read a huge text file through javascript or jquery? - Stack Overflow

    How can I read a huge text file line by line through javascript or jquery?I cant read all and split to

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信