javascript - Parsing Binary Files in Client-side JS - Stack Overflow

I'm wondering if there's any possible way of parsing a binary file in client-side Javascript.

I'm wondering if there's any possible way of parsing a binary file in client-side Javascript. I would like to write a page that contains an HTML input form for a binary file ( a sound file is the end game ) and a button that activates a Javascript function that 'parses' the file. Is this possible with client-side Javascript?

I know I can do this with C on the server, but I'd like to avoid anything server-side involved. This is because I'm expecting the task to be putationally intensive and I would like to keep the load and the server low.

From what I've seen on Google, it's possible to parse binary data in Javascript. I'm just not sure how to get the file in the hands of a Javascript function without first passing it to the server.

I'm wondering if there's any possible way of parsing a binary file in client-side Javascript. I would like to write a page that contains an HTML input form for a binary file ( a sound file is the end game ) and a button that activates a Javascript function that 'parses' the file. Is this possible with client-side Javascript?

I know I can do this with C on the server, but I'd like to avoid anything server-side involved. This is because I'm expecting the task to be putationally intensive and I would like to keep the load and the server low.

From what I've seen on Google, it's possible to parse binary data in Javascript. I'm just not sure how to get the file in the hands of a Javascript function without first passing it to the server.

Share Improve this question asked May 11, 2013 at 8:06 tay10rtay10r 4,3572 gold badges27 silver badges45 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You can use the FileReader API to read a file client-side

Example:

HTML Markup:

<input id="myfile" type="file"/>

JavaScript:

var fileInput = document.getElementById('myfile');
var fReader = new FileReader();

fReader.onload = function(e) {
  console.log(e.target.result); /// <-- this contains an ArrayBuffer
}

fileInput.onchange = function(e) {
    var file = this.files[0];
    fReader.readAsArrayBuffer(file);
}

JSFiddle: http://jsfiddle/wbwHU/ (look at the console for ArrayBuffer output)

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

相关推荐

  • javascript - Parsing Binary Files in Client-side JS - Stack Overflow

    I'm wondering if there's any possible way of parsing a binary file in client-side Javascript.

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信