Content-Length: 321452 | pFad | http://github.com/roygdavis/SamExif/commit/a24573605a58c65ea8a8b922d2c7b8030ae9c9cd

2F fromBuffer · roygdavis/SamExif@a245736 · GitHub
Skip to content

Commit

Permalink
fromBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Jul 29, 2018
1 parent 4f25e76 commit a245736
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
27 changes: 20 additions & 7 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.js.map

Large diffs are not rendered by default.

27 changes: 20 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,15 @@ function APPnHandler(buffer) {
}

/**
* @param file {String}
* @param buffer {Buffer}
* @returns {Object}
* @example
* var exif = sync("~/Picture/IMG_1981.JPG");
* console.log(exif.createTime);
*/
function sync(file) {
if (!file) {
throw new Error('File not found');
function fromBuffer(buffer) {
if (!buffer) {
throw new Error('buffer not found');
}
data = undefined;
let buffer = fs.readFileSync(file);
if (isValid(buffer)) {
buffer = buffer.slice(SOIMarkerLength);
data = {};
Expand All @@ -250,6 +247,21 @@ function sync(file) {
return data;
}

/**
* @param file {String}
* @returns {Object}
* @example
* var exif = sync("~/Picture/IMG_1981.JPG");
* console.log(exif.createTime);
*/
function sync(file) {
if (!file) {
throw new Error('File not found');
}
let buffer = fs.readFileSync(file);
return fromBuffer(buffer);
}

/**
* @param file {String}
* @param callback {Function}
Expand Down Expand Up @@ -296,5 +308,6 @@ function async(file, callback) {
});
}

exports.fromBuffer = fromBuffer;
exports.parse = async;
exports.parseSync = sync;
26 changes: 26 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global it, describe */
const fs = require('fs');
const { expect } = require('chai');
const exif = require('../lib/index.js');

Expand Down Expand Up @@ -68,3 +69,28 @@ describe('.parseSync()', () => {
expect(data.GPSInfo).to.be.an('object');
});
});
describe('.fromBuffer()', () => {
it('file {undefined}', () => {
expect(exif.fromBuffer).to.throw(Error);
});
it('APP1:#0xffe1', () => {
const buffer = fs.readFileSync('./test/IMG_0001.JPG');
const data = exif.fromBuffer(buffer);
expect(data).to.be.an('object');
});
it('!APP1:#0xffe1', () => {
const buffer = fs.readFileSync('./test/IMG_0003.JPG');
const data = exif.fromBuffer(buffer);
expect(data).to.be.an('object');
});
it('[SubExif]', () => {
const buffer = fs.readFileSync('./test/IMG_0001.JPG');
const data = exif.fromBuffer(buffer);
expect(data.SubExif).to.be.an('object');
});
it('[GPSInfo]', () => {
const buffer = fs.readFileSync('./test/IMG_0001.JPG');
const data = exif.fromBuffer(buffer);
expect(data.GPSInfo).to.be.an('object');
});
});

0 comments on commit a245736

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/roygdavis/SamExif/commit/a24573605a58c65ea8a8b922d2c7b8030ae9c9cd

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy