Skip to content

Commit

Permalink
Fixed inserting binary files (problem with image dimension).
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Feb 10, 2016
1 parent 2e5be70 commit b7e0cff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions index.js
Expand Up @@ -2,7 +2,7 @@
* @module NoSQL Embedded Database
* @author Peter Širka <petersirka@gmail.com>
* @copyright Peter Širka 2012-2016
* @version 3.1.0
* @version 3.1.1
*/

'use strict';
Expand Down Expand Up @@ -1970,7 +1970,7 @@ Binary.prototype.insert = function(name, type, buffer, fnCallback, changes) {

var self = this;
var size = buffer.length;
var dimension = { width: 0, height: 0 };
var dimension;

self.check();

Expand All @@ -1981,6 +1981,9 @@ Binary.prototype.insert = function(name, type, buffer, fnCallback, changes) {
else if (name.indexOf('.jpg') !== -1)
dimension = dimensionJPG(buffer);

if (!dimension)
dimension = { width: 0, height: 0 };

var header = new Buffer(BINARY_HEADER_LENGTH);
header.fill(' ');
header.write(JSON.stringify({ name: name, size: size, type: type, width: dimension.width, height: dimension.height }));
Expand Down Expand Up @@ -2061,7 +2064,7 @@ Binary.prototype.update = function(id, name, type, buffer, fnCallback, changes)

var self = this;
var size = buffer.length;
var dimension = { width: 0, height: 0 };
var dimension;
var key = id;

self.check();
Expand All @@ -2076,6 +2079,9 @@ Binary.prototype.update = function(id, name, type, buffer, fnCallback, changes)
else if (name.indexOf('.jpg') !== -1)
dimension = dimensionJPG(buffer);

if (!dimension)
dimension = { width: 0, height: 0 };

var header = new Buffer(BINARY_HEADER_LENGTH);
header.fill(' ');
header.write(JSON.stringify({ name: name, size: size, type: type, width: dimension.width, height: dimension.height }));
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "nosql",
"version": "3.1.0",
"version": "3.1.1",
"description": "NoSQL embedded database for small node.js projects (supports insert, update, remove, views, drop, stored)",
"main": "./index.js",
"keywords": [ "nosql", "database", "embed", "embedded", "db", "binary"],
Expand Down

0 comments on commit b7e0cff

Please sign in to comment.