ers.get('Content-Type');
    if (contentType !== 'application/wasm') {
      throw new ERR_WEBASSEMBLY_RESPONSE(
        `has unsupported MIME type '${contentType}'`);
    }

    if (!response.ok) {
      throw new ERR_WEBASSEMBLY_RESPONSE(
        `has status code ${response.status}`);
    }

    if (response.bodyUsed !== false) {
      throw new ERR_WEBASSEMBLY_RESPONSE('body has already been used');
    }

    if (response.url) {
      streamState.setURL(response.url);
    }

    // Pass all data from the response body to the WebAssembly compiler.
    const { body } = response;
    if (body != null) {
      for await (const chunk of body) {
        streamState.push(chunk);
      }
    }
  })().then(() => {
    // No error occurred. Tell the implementation that the stream has ended.
    streamState.finish();
  }, (err) => {
    // An error occurred, either because the given object was not a valid
    // and usable Response or because a network error occurred.
    streamState.abort(err);
  });
}

module.exports = {
  wasmStreamingCallback,
};
