如何下载/阅读文件的只有第一个80KB? [英] How to download/read only the first 80KB of a file?

查看:133
本文介绍了如何下载/阅读文件的只有第一个80KB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个的Greasemonkey脚本的网站,有很多Flash文件。我想使闪光灯的哈希值,问题是闪存文件多达10兆字节。

I am making a Greasemonkey script for a website that has many flash files. I'd like to make a hash of the flash, the problem is that the flash files are up to 10 megabytes.

这是缓慢的;我希望能够只抢到第一80KB凑。最终的结果将是一个简单的方法来黑名单包含恶意内容的某些Flash文件。 如何做一个文件我的脚本只抢前80 KB(左右)?

This is slow; I'd like to be able to only grab the first 80KB to hash. The end result would be an easy way to blacklist certain flash files containing unwanted content. How does my script grab only the first 80 KB (or so) of a file?

推荐答案

发送范围在你的AJAX请求。

Send the range header in your AJAX request.

例如:

$.ajax ( {
    url:        'http://TARGET_SERVER.COM/TARGET_PATH/TARGET_FILE.FLV',
    headers:    { Range: "bytes=0-80000" },
    success:    function (Resp) {
                    console.log(Resp);
                }
} );

(对于那些在相同的域为目标页的文件。)

(For files that are on the same-domain as the target page.)


对于跨域文件使用 GM_xmlhtt prequest()


For cross-domain files use GM_xmlhttpRequest():

GM_xmlhttpRequest ( {
    method:     "GET",
    url:        'http://TARGET_SERVER.COM/TARGET_PATH/TARGET_FILE.FLV',
    headers:    { Range: "bytes=0-80000" },
    onload:     function (Resp) {
                    console.log(Resp.responseText);
                }
} );

这篇关于如何下载/阅读文件的只有第一个80KB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆