try { var b = new Blob(['hi']); return b.size == 2; } catch(e) { return false;
(function () { try { return new Blob([new Uint8Array(100)]).size === 100 } catch (e) { return false
it('can construct a Blob when called with an empty Array', function () { var blob = new Blob([]); proclaim.equal(blob.size, 0); proclaim.equal(blob.type, ''); });
(function() { try { var b = new Blob(['hi']); return b.size == 2; } catch(e) { return false; } })()
// 鉴于浏览器默认不会显示图片的体积大小,每次都需要保存到本地才能查看到大小 // 故通过插件的方式强行修改图片页的标题 fetch(location.href).then(resp => resp.blob()).then(blob => { var size = blob.size; size = (size / 1024).toFixed(2) + ' kb'; document.title = '(' + size + ')' + document.title; console.log(size); });
test('from text', async t => { const blob = new Blob(['hello']); t.isEqual(blob.size, 5, 'is right size'); t.isEqual(blob.type, '', 'type is empty'); t.isEqual(await blob.text(), 'hello', 'reads as text'); t.isEquivalent(new Uint8Array(await blob.arrayBuffer()), [ ...'hello'.split('').map(char => char.charCodeAt(0)) ]); });
it('uses first argument of slice to decide where to start the slice', function () { var blob1 = new Blob(['test']); var blob2 = blob1.slice(1); proclaim.equal(blob2.size, 3); });
(function() { try { var b = new Blob([new Uint8Array([1,2])]); return b.size === 2; } catch(e) { return false; } })()
test('no args', async t => { const blob = new Blob(); t.isEqual(blob.size, 0, 'size is 0'); t.isEqual(blob.type, '', 'type is empty'); t.isEqual(await blob.text(), '', 'reads as text'); t.isEquivalent(await blob.arrayBuffer(), new ArrayBuffer(0), 'returns empty buffer'); });
it('should use the type property of the second argument as the type property on the returned Blob object', function () { var blob = new Blob([], { type: 'test' }); proclaim.equal(blob.size, 0); proclaim.equal(blob.type, 'test'); });
it('uses second argument of slice to decide where to end the slice', function () { var blob1 = new Blob(['test']); var blob2 = blob1.slice(0, 1); proclaim.equal(blob2.size, 1); });
(function() { try { var a = new Blob(['hi']); return a.size === 2; } catch(e) { return false; } })()
it('can construct a Blob when called with an Array', function () { var blob = new Blob([null, true, false, 0, 1, 1.5, 'fail', {}]); proclaim.equal(blob.size, 37); proclaim.equal(blob.type, ''); });
it('if second argument of slice is less than first argument, return an empty blob', function () { var blob1 = new Blob(['test']); var blob2 = blob1.slice(2,1); proclaim.equal(blob2.size, 0); });
(function() { try { var a = new Blob(['hi']); return a.size === 2; } catch(e) { return false; } })()