Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Microsoft Edge中创建ReadableStream?_Javascript_Microsoft Edge_Web Standards - Fatal编程技术网

Javascript 如何在Microsoft Edge中创建ReadableStream?

Javascript 如何在Microsoft Edge中创建ReadableStream?,javascript,microsoft-edge,web-standards,Javascript,Microsoft Edge,Web Standards,以及Microsoft Edge自己的页面声明,自版本号16299+(2017年9月26日发布)以来,Microsoft Edge支持ReadableStream 但是,当我尝试在最新的Edge(Microsoft Edge 44.17763.1.0,Microsoft EdgeHTML 18.17763)中创建ReadableStream时,我得到了预期的错误函数 两者 及 抛出预期的函数错误。省略新的也不起作用 我做错了什么?您可以尝试使用以下代码读取Edge中的数据: function p

以及Microsoft Edge自己的页面声明,自版本号16299+(2017年9月26日发布)以来,Microsoft Edge支持
ReadableStream

但是,当我尝试在最新的Edge(Microsoft Edge 44.17763.1.0,Microsoft EdgeHTML 18.17763)中创建ReadableStream时,我得到了预期的错误
函数

两者

抛出预期的
函数
错误。省略新的
也不起作用


我做错了什么?

您可以尝试使用以下代码读取Edge中的数据:

function pump(reader, context) {
    return reader.read().then(function (result) {
        if (result.done) {
            console.log('ReadableStreamReader: complete! Received ' + context.receivedLength);
        } else {
            var chunk = result.value;
            console.log('ReadableStreamReader: Partial chunk, chunkSize = ' + chunk.byteLength);

            context.receivedLength += chunk.byteLength;
            return pump(reader, context);
        }
    }).catch(function (e) {
        throw e;
    });
}

function fetchVideo() {
    var url = 'xxxxxxxx';

    var headers = new Headers();
    var param = {
        method: 'GET',
        headers: headers,
        mode: 'cors',
        cache: 'default'
    };

    var context = {
        receivedLength: 0
    };

    fetch(url, param).then(function (res) {
        console.log('Content-Length: ' + res.headers.get('Content-Length'));
        return pump(res.body.getReader(), context);
    }).catch(function (e) {
        throw e;
    });
}

您可以尝试使用以下代码读取Edge中的数据:

function pump(reader, context) {
    return reader.read().then(function (result) {
        if (result.done) {
            console.log('ReadableStreamReader: complete! Received ' + context.receivedLength);
        } else {
            var chunk = result.value;
            console.log('ReadableStreamReader: Partial chunk, chunkSize = ' + chunk.byteLength);

            context.receivedLength += chunk.byteLength;
            return pump(reader, context);
        }
    }).catch(function (e) {
        throw e;
    });
}

function fetchVideo() {
    var url = 'xxxxxxxx';

    var headers = new Headers();
    var param = {
        method: 'GET',
        headers: headers,
        mode: 'cors',
        cache: 'default'
    };

    var context = {
        receivedLength: 0
    };

    fetch(url, param).then(function (res) {
        console.log('Content-Length: ' + res.headers.get('Content-Length'));
        return pump(res.body.getReader(), context);
    }).catch(function (e) {
        throw e;
    });
}

根据,我在Edge 44上重现了这个问题,但在Edge 42上效果很好。因此,我认为这个问题与Edge 44有关,作为一种解决方法,我建议您可以尝试将Edge版本降级为42版本。并且,我将尝试将此问题反馈给Edge平台。

根据,我在Edge 44上重现了此问题,但在Edge 42上效果良好。因此,我认为这个问题与Edge 44有关,作为一种解决方法,我建议您可以尝试将Edge版本降级为42版本。而且,我会尝试将这个问题反馈给Edge平台。

它在另一个浏览器中工作吗?在Chrome和Firefox中工作吗?在Chrome和Firefox中工作吗?不幸的是,这不允许我创建一个我可以控制的可读流,所以不幸的是,这不是我想要的,这不允许我创建一个我可以控制的ReadableStream,所以这不是我想要的
function pump(reader, context) {
    return reader.read().then(function (result) {
        if (result.done) {
            console.log('ReadableStreamReader: complete! Received ' + context.receivedLength);
        } else {
            var chunk = result.value;
            console.log('ReadableStreamReader: Partial chunk, chunkSize = ' + chunk.byteLength);

            context.receivedLength += chunk.byteLength;
            return pump(reader, context);
        }
    }).catch(function (e) {
        throw e;
    });
}

function fetchVideo() {
    var url = 'xxxxxxxx';

    var headers = new Headers();
    var param = {
        method: 'GET',
        headers: headers,
        mode: 'cors',
        cache: 'default'
    };

    var context = {
        receivedLength: 0
    };

    fetch(url, param).then(function (res) {
        console.log('Content-Length: ' + res.headers.get('Content-Length'));
        return pump(res.body.getReader(), context);
    }).catch(function (e) {
        throw e;
    });
}