You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/pitfall/pdfkit/node_modules/blob-stream/test/index.js

74 lines
1.6 KiB
JavaScript

var blobStream = require('../');
var test = require('tape');
test('buffers', function(t) {
var s = blobStream();
s.on('finish', function() {
t.equal(this.length, 6);
var blob = this.toBlob();
t.equal(blob.size, 6);
t.equal(blob.type, 'application/octet-stream');
blob = this.toBlob('text/plain');
t.equal(blob.size, 6);
t.equal(blob.type, 'text/plain');
t.equal(typeof this.toBlobURL(), 'string');
t.end();
});
s.write(new Buffer('abc'));
s.end(new Buffer('def'));
});
test('arrays', function(t) {
var s = blobStream();
s.on('finish', function() {
t.equal(this.length, 6);
var blob = this.toBlob();
t.equal(blob.size, 6);
t.equal(blob.type, 'application/octet-stream');
blob = this.toBlob('text/plain');
t.equal(blob.size, 6);
t.equal(blob.type, 'text/plain');
t.equal(typeof this.toBlobURL(), 'string');
t.end();
});
var uta = Buffer._useTypedArrays;
Buffer._useTypedArrays = false;
s.write(new Buffer('abc'));
s.end(new Buffer('def'));
Buffer._useTypedArrays = uta;
});
test('sliced buffers', function(t) {
var s = blobStream();
s.on('finish', function() {
t.equal(this.length, 4);
var blob = this.toBlob();
t.equal(blob.size, 4);
t.equal(blob.type, 'application/octet-stream');
blob = this.toBlob('text/plain');
t.equal(blob.size, 4);
t.equal(blob.type, 'text/plain');
t.equal(typeof this.toBlobURL(), 'string');
t.end();
});
s.write(new Buffer('abc').slice(1));
s.end(new Buffer('def').slice(0, -1));
});