(() => { try { return !!new Blob(); } catch (e) { return false; } })()
export function readBlob(blob) { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onend = reject; reader.onabort = reject; reader.onload = () => resolve(reader.result); reader.readAsDataURL(new Blob([blob], { type: blob.type })); }); }
set complete (_bool) { if (!_bool || _bool === 'false') return this._complete = true this.style.color = 'blue' this.style.cursor = 'pointer' this.onclick = async () => { let arrayBuffers = await this.getArrayBuffers() let blob = new Blob(arrayBuffers, {type: this.contentType}) let url = URL.createObjectURL(blob) let a = document.createElement('a') a.setAttribute('href', url) a.setAttribute('download', this.filename) a.click() } }
const saveRequests = ( requests ) => { const requestData = {}; requests.forEach( ( value, key ) => { const path = JSON.parse( key ).path; if ( ! requestData.hasOwnProperty( path ) ) { requestData[ path ] = {}; } requestData[ path ][ key ] = value; } ); const file = new Blob( [ JSON.stringify( requestData, null, 2 ) ], { type: 'application/json', } ); const url = URL.createObjectURL( file ); window.open( url ); }
set complete (value) { // TODO: wire up save button. let f = this.filename let save = bel`<span title="${f}" class="action-link">Save</span>` save.onclick = async () => { let blob = new Blob(this.chunks, {type: this.contentType}) let url = URL.createObjectURL(blob) let a = document.createElement('a') a.setAttribute('href', url) a.setAttribute('download', this.filename) a.click() } this.action = save this.blockRemoval = true }
const zip = async (id) => { await loadjs([{async: true, url: jszip}]) var zip = new JSZip() // Generate a directory within the Zip file structure var folder = zip.folder(`rollcall-${id}`) // Add a file to the directory, in this case an image with data URI as contents let sel = 'roll-call-recorder-file' for (let n of document.querySelectorAll(sel)) { let arrayBuffers = await n.getArrayBuffers() let blob = new Blob(arrayBuffers, {type: n.contentType}) folder.file(n.filename, blob) } let opts = {type: 'audio/webm'} let blob = new Blob(files[`${id}-monitor.webm`], opts) folder.file(`${id}-monitor.webm`, blob) return zip.generateAsync({type: 'blob'}) }
formData.append('blob', new Blob(['blob'], { type: 'text/plain' })); formData.append( 'file',
new Blob( [ arr ], { type: polyfillType || 'image/png', } )
cy .fixture(fileUrl, 'base64') .then(Cypress.Blob.base64StringToBlob) .then(blob => { const el = subject[0];
describe('Unit | Utils | Serializers | blob', function() { serializerTests(serialize); it('should noop if Blob is not found', function() { const Blob = Blob; const blob = new Blob(['blob'], { type: 'text/plain' }); global.Blob = undefined; expect(serialize(blob)).to.be.equal(blob); global.Blob = Blob; }); it('should handle blobs', async function() { expect( await serialize(new Blob(['blob'], { type: 'text/plain' })) ).to.equal(`data:text/plain;base64,${btoa('blob')}`); }); it('should handle files', async function() { expect( await serialize( new File(['file'], 'file.txt', { type: 'text/plain' }) ) ).to.equal(`data:text/plain;base64,${btoa('file')}`); }); });
(() => { try { return !!new Blob(); } catch (e) { return false; } })()
export function readBlob(blob) { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onend = reject; reader.onabort = reject; reader.onload = () => resolve(reader.result); reader.readAsDataURL(new Blob([blob], { type: blob.type })); }); }
describe('Unit | Utils | Serializers | blob', function() { serializerTests(serialize); it('should noop if Blob is not found', function() { const Blob = Blob; const blob = new Blob(['blob'], { type: 'text/plain' }); global.Blob = undefined; expect(serialize(blob)).to.be.equal(blob); global.Blob = Blob; }); it('should handle blobs', async function() { expect( await serialize(new Blob(['blob'], { type: 'text/plain' })) ).to.equal(`data:text/plain;base64,${btoa('blob')}`); }); it('should handle files', async function() { expect( await serialize( new File(['file'], 'file.txt', { type: 'text/plain' }) ) ).to.equal(`data:text/plain;base64,${btoa('file')}`); }); });
formData.append('blob', new Blob(['blob'], { type: 'text/plain' })); formData.append( 'file',