mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add support for writing dz format to zip container (#402)
To enable this you can either use the `.zip` or `.szi` file extensions
or use `.tile({container: 'zip'})` with the `.dzi` extension.
This commit is contained in:
committed by
Lovell Fuller
parent
ef61da3051
commit
b224874332
@@ -6,6 +6,7 @@ var assert = require('assert');
|
||||
|
||||
var async = require('async');
|
||||
var rimraf = require('rimraf');
|
||||
var unzip = require('unzip');
|
||||
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
@@ -88,6 +89,26 @@ describe('Tile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid container values pass', function() {
|
||||
['fs', 'zip'].forEach(function(container) {
|
||||
assert.doesNotThrow(function() {
|
||||
sharp().tile({
|
||||
container: container
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid container values fail', function() {
|
||||
['zoinks', 1].forEach(function(container) {
|
||||
assert.throws(function() {
|
||||
sharp().tile({
|
||||
container: container
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid layout values pass', function() {
|
||||
['dz', 'google', 'zoomify'].forEach(function(layout) {
|
||||
assert.doesNotThrow(function() {
|
||||
@@ -190,6 +211,58 @@ describe('Tile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Write to ZIP container using file extension', function(done) {
|
||||
var container = fixtures.path('output.dz.container.zip');
|
||||
var extractTo = fixtures.path('output.dz.container');
|
||||
var directory = path.join(extractTo, 'output.dz.container_files');
|
||||
rimraf(directory, function() {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toFile(container, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
fs.stat(container, function(err, stat) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
fs.createReadStream(container)
|
||||
.pipe(unzip.Extract({path: path.dirname(extractTo)}))
|
||||
.on('error', function(err) { throw err; })
|
||||
.on('close', function() {
|
||||
assertDeepZoomTiles(directory, 256, 13, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Write to ZIP container using container tile option', function(done) {
|
||||
var container = fixtures.path('output.dz.containeropt.zip');
|
||||
var extractTo = fixtures.path('output.dz.containeropt');
|
||||
var directory = path.join(extractTo, 'output.dz.containeropt_files');
|
||||
rimraf(directory, function() {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
container: 'zip'
|
||||
})
|
||||
.toFile(fixtures.path('output.dz.containeropt.dzi'), function(err, info) {
|
||||
// Vips overrides .dzi extension to .zip used by container var below
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
fs.stat(container, function(err, stat) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
fs.createReadStream(container)
|
||||
.pipe(unzip.Extract({path: path.dirname(extractTo)}))
|
||||
.on('error', function(err) { throw err; })
|
||||
.on('close', function() {
|
||||
assertDeepZoomTiles(directory, 256, 13, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user