- From: Sven Franck <notifications@github.com>
- Date: Sun, 17 Apr 2016 10:49:12 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Message-ID: <whatwg/streams/issues/438@github.com>
I'm trying to work with serviceworker resulting in my first encounter with a ReadableByteStream. I learned from [here](https://jakearchibald.com/2015/thats-so-fetch/) that I can call **blob()** on a stream which as the method implies returns a blob. However, my blob has no mime-type set and as [type is readonly](https://developer.mozilla.org/en-US/docs/Web/API/Blob), there is no way to pass the info available (passed back as header content-type) into the call to **blob()**. Here is an example: // STORE AS BLOB // param.name = "http://foo.css", // param.content = new Blob( // ["span%2C%20div%20%7Bborder%3A%201px%20solid%20red%20!important%3B%7D"], // {type: "text/css"} // ) caches.open(CURRENT_CACHE) .then(function(cache) { request = new Request(param.name, {mode: 'no-cors'}), response = new Response(param.content); return cache.put(request, response); }); // FETCH BLOB: caches.open(CURRENT_CACHE) .then(function(cache) { return cache.match("http://foo.css") }).then(function(answer) { console.log(answer.body); // ReadableByteStream console.log(answer.headers.get('Content-Type')); // text/css // CALLING blob() - cannot pass mime-type return answer.clone().blob() }).then(function(my_blob) { console.log(my_blob); console.log(my_blob.type); // undefined }); If I have to return a blob with mime-type set, the only way I see is read out the blob content and store them in a new blob using the content-type retrieved from the header. Hence I was wondering whether there is a plan for being able to set the mime-type when calling **blob()**? Otherwise... cool stuff! --- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/streams/issues/438
Received on Sunday, 17 April 2016 17:49:39 UTC