Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

javascript - Can I use the HTTP range header to load partial files "on purpose"?

I'm playing around with the HTTP range header (specs).

From what I understand I can set byte ranges of files ala

0-199/2000
200-499/2000
500-799/2000
etc

Question:
Say I only want to access certain ranges of a file, would it be possible to specify these ranges and then work with the "incomplete" data I received? I'm playing around with filtering a large log file, so I'm curious if something like this would work.

Thanks for inputs!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are right the link which you posted in the comment would be probably the best approche. As your question sounded interesting i tried it out. You probably did it, but here is an snippet(for other that may come looking)

var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","data.dat",false);
xmlhttp.setRequestHeader("Range", "bytes=100-200");
xmlhttp.send();
console.info(xmlhttp); //--> returns only the partial content
// Tested on Win7 with chrome 46+

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...