Tile-based output filename may not exist, check g_stat return value

This commit is contained in:
Lovell Fuller 2016-11-06 14:31:28 +00:00
parent 9911863441
commit a7b024d4fa
2 changed files with 127 additions and 104 deletions

View File

@ -917,8 +917,9 @@ class PipelineWorker : public Nan::AsyncWorker {
} else { } else {
// Add file size to info // Add file size to info
GStatBuf st; GStatBuf st;
g_stat(baton->fileOut.data(), &st); if (g_stat(baton->fileOut.data(), &st) == 0) {
Set(info, New("size").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(st.st_size))); Set(info, New("size").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(st.st_size)));
}
argv[1] = info; argv[1] = info;
} }
} }

View File

@ -140,7 +140,6 @@ describe('Tile', function () {
}); });
}); });
if (sharp.format.dz.output.file) {
it('Deep Zoom layout', function (done) { it('Deep Zoom layout', function (done) {
const directory = fixtures.path('output.dzi_files'); const directory = fixtures.path('output.dzi_files');
rimraf(directory, function () { rimraf(directory, function () {
@ -148,6 +147,10 @@ describe('Tile', function () {
.toFile(fixtures.path('output.dzi'), function (err, info) { .toFile(fixtures.path('output.dzi'), function (err, info) {
if (err) throw err; if (err) throw err;
assert.strictEqual('dz', info.format); assert.strictEqual('dz', info.format);
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('undefined', typeof info.size);
assertDeepZoomTiles(directory, 256, 13, done); assertDeepZoomTiles(directory, 256, 13, done);
}); });
}); });
@ -164,6 +167,10 @@ describe('Tile', function () {
.toFile(fixtures.path('output.512.dzi'), function (err, info) { .toFile(fixtures.path('output.512.dzi'), function (err, info) {
if (err) throw err; if (err) throw err;
assert.strictEqual('dz', info.format); assert.strictEqual('dz', info.format);
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('undefined', typeof info.size);
assertDeepZoomTiles(directory, 512 + 2 * 16, 13, done); assertDeepZoomTiles(directory, 512 + 2 * 16, 13, done);
}); });
}); });
@ -179,6 +186,10 @@ describe('Tile', function () {
.toFile(fixtures.path('output.zoomify.dzi'), function (err, info) { .toFile(fixtures.path('output.zoomify.dzi'), function (err, info) {
if (err) throw err; if (err) throw err;
assert.strictEqual('dz', info.format); assert.strictEqual('dz', info.format);
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) { fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, stat.isFile()); assert.strictEqual(true, stat.isFile());
@ -199,6 +210,10 @@ describe('Tile', function () {
.toFile(directory, function (err, info) { .toFile(directory, function (err, info) {
if (err) throw err; if (err) throw err;
assert.strictEqual('dz', info.format); assert.strictEqual('dz', info.format);
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) { fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, stat.isFile()); assert.strictEqual(true, stat.isFile());
@ -218,6 +233,10 @@ describe('Tile', function () {
.toFile(container, function (err, info) { .toFile(container, function (err, info) {
if (err) throw err; if (err) throw err;
assert.strictEqual('dz', info.format); assert.strictEqual('dz', info.format);
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
fs.stat(container, function (err, stat) { fs.stat(container, function (err, stat) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, stat.isFile()); assert.strictEqual(true, stat.isFile());
@ -246,6 +265,10 @@ describe('Tile', function () {
// Vips overrides .dzi extension to .zip used by container var below // Vips overrides .dzi extension to .zip used by container var below
if (err) throw err; if (err) throw err;
assert.strictEqual('dz', info.format); assert.strictEqual('dz', info.format);
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
fs.stat(container, function (err, stat) { fs.stat(container, function (err, stat) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, stat.isFile()); assert.strictEqual(true, stat.isFile());
@ -260,5 +283,4 @@ describe('Tile', function () {
}); });
}); });
}); });
}
}); });