mirror of
https://github.com/nolanlawson/blob-util.git
synced 2025-12-08 19:46:19 +00:00
more tests
This commit is contained in:
parent
fdf181c6ba
commit
4a2c56c649
2
index.js
2
index.js
@ -86,10 +86,12 @@ function loadImage(src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dataURLToBlob(dataURL) {
|
function dataURLToBlob(dataURL) {
|
||||||
|
return Promise.resolve().then(function () {
|
||||||
var type = dataURL.match(/data:([^;]+)/)[1];
|
var type = dataURL.match(/data:([^;]+)/)[1];
|
||||||
var base64 = dataURL.replace(/^[^,]+,/, '');
|
var base64 = dataURL.replace(/^[^,]+,/, '');
|
||||||
|
|
||||||
return createBlob([binaryStringToArrayBuffer(atob(base64))], {type: type});
|
return createBlob([binaryStringToArrayBuffer(atob(base64))], {type: type});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createObjectURL(blob) {
|
function createObjectURL(blob) {
|
||||||
|
|||||||
@ -14,6 +14,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="mocha"></div>
|
<div id="mocha"></div>
|
||||||
<img src="kirby.gif" id="kirby"/>
|
<img src="kirby.gif" id="kirby"/>
|
||||||
|
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII="
|
||||||
|
id="transparent"/>
|
||||||
<script type="text/javascript" src="./webrunner.js"></script>
|
<script type="text/javascript" src="./webrunner.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
16
test/test.js
16
test/test.js
@ -86,5 +86,21 @@ function tests() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('convert data url', function () {
|
||||||
|
var dataURL = 'data:image/png;base64,' + transparent1x1Png;
|
||||||
|
return blobUtil.dataURLToBlob(dataURL).then(function (blob) {
|
||||||
|
return blobUtil.blobToBase64String(blob);
|
||||||
|
}).then(function (string) {
|
||||||
|
string.should.equal(transparent1x1Png);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('convert to dataURL', function () {
|
||||||
|
var img = document.getElementById('transparent');
|
||||||
|
return blobUtil.imgSrcToDataURL(img.src).then(function (url) {
|
||||||
|
url.should.match(/^data:image\/png;base64/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user