Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jul 28, 2016
0 parents commit 2a6b1e6
Show file tree
Hide file tree
Showing 13 changed files with 432 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
coverage/
node_modules/
npm-debug.log
dist/
typings/
vendor/
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sudo: false
language: node_js

notifications:
email:
on_success: never
on_failure: change

node_js:
- "iojs"
- "4"
- "stable"

after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2016 Blake Embrey

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Exiftool2

[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

> Wrapper for efficiently working with `exiftool`.
## Installation

```sh
npm install exiftool2 --save
```

## Usage

```js
import { exec, open } from 'exiftool2'

// Pass arguments to create an instance of `exiftool` parsing.
// Default arguments: -q -json
// Read more: http://linux.die.net/man/1/exiftool
const exif = exec(['-fast', 'placeholder.png'])

exif.on('exif', ...)
exif.on('error', ...)

// Create an instance that defaults to `-stay_open`.
// Identical to `exec`, except for the default arguments.
// Default arguments: -stay_open True -@ -
const exif = open(['-fast', 'placeholder.png'])

// Push commands to `-execute`. Prepends `-q -json` to each `send()`.
exif.send(['placeholder.png'])

// Pushes `-stay_open False` to be executed, closing `exiftool`.
exif.close()

exif.on('exif', ...)
exif.on('error', ...)
```

## License

Apache 2.0

[npm-image]: https://img.shields.io/npm/v/exiftool2.svg?style=flat
[npm-url]: https://npmjs.org/package/exiftool2
[downloads-image]: https://img.shields.io/npm/dm/exiftool2.svg?style=flat
[downloads-url]: https://npmjs.org/package/exiftool2
[travis-image]: https://img.shields.io/travis/blakeembrey/node-exiftool2.svg?style=flat
[travis-url]: https://travis-ci.org/blakeembrey/node-exiftool2
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/node-exiftool2.svg?style=flat
[coveralls-url]: https://coveralls.io/r/blakeembrey/node-exiftool2?branch=master
52 changes: 52 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "exiftool2",
"version": "0.0.0",
"description": "Wrapper for efficiently working with `exiftool`",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist/",
"vendor/"
],
"scripts": {
"lint": "tslint \"src/**/*.ts\"",
"build": "rm -rf dist && tsc",
"test-spec": "blue-tape 'dist/**/*.spec.js' | tap-spec",
"test-cov": "istanbul cover --print none -x '*.spec.js' node_modules/blue-tape/bin/blue-tape.js -- 'dist/**/*.spec.js' | tap-spec",
"test": "npm run build && npm run lint && npm run test-cov",
"prepublish": "npm run vendor && typings install && npm run build",
"vendor": "[ ! -f vendor/Image-ExifTool-10.24/exiftool ] && npm run bundle || true",
"bundle": "curl -L http://www.sno.phy.queensu.ca/~phil/exiftool/Image-ExifTool-10.24.tar.gz | tar xz -C vendor"
},
"repository": {
"type": "git",
"url": "git://github.com/blakeembrey/node-exiftool2.git"
},
"keywords": [
"exif",
"exiftool",
"image",
"metadata",
"parser",
"extract"
],
"author": {
"name": "Blake Embrey",
"email": "hello@blakeembrey.com",
"url": "http://blakeembrey.me"
},
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/blakeembrey/node-exiftool2/issues"
},
"homepage": "https://github.com/blakeembrey/node-exiftool2",
"devDependencies": {
"blue-tape": "^0.2.0",
"istanbul": "^0.4.4",
"tap-spec": "^4.1.1",
"tslint": "^3.13.0",
"tslint-config-standard": "^1.3.0",
"typescript": "^1.8.10",
"typings": "^1.3.0"
}
}
127 changes: 127 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import test = require('blue-tape')
import { createReadStream } from 'fs'
import { join } from 'path'
import { exec, open, execSync } from './index'

const FIXTURE_DIR = join(__dirname, '../test/fixtures')

test('exiftool2', t => {
t.test('pipe png', t => {
const exif = exec(['-fast', '-'])

createReadStream(join(FIXTURE_DIR, 'placeholder.png')).pipe(exif)

exif.on('exif', (exif) => {
t.equal(exif.length, 1)
t.equal(exif[0].FileType, 'PNG')

t.end()
})
})

t.test('pipe jpeg', t => {
const exif = exec(['-'])

createReadStream(join(FIXTURE_DIR, 'subway.jpeg')).pipe(exif)

exif.on('exif', (exif) => {
t.equal(exif.length, 1)
t.equal(exif[0].FileType, 'JPEG')

t.end()
})
})

t.test('filename', t => {
const exif = exec(['-fast', join(FIXTURE_DIR, 'placeholder.png')])

exif.on('exif', (exif) => {
t.equal(exif.length, 1)
t.equal(exif[0].FileType, 'PNG')

t.end()
})
})

t.test('short output', t => {
const exif = exec(['-S', join(FIXTURE_DIR, 'placeholder.png')])

exif.on('exif', (exif) => {
t.equal(exif.length, 1)
t.equal(exif[0].FileType, 'PNG')

t.end()
})
})

t.test('group output', t => {
const exif = exec(['-g', join(FIXTURE_DIR, 'placeholder.png')])

exif.on('exif', (exif) => {
t.equal(exif.length, 1)
t.equal(exif[0].File.FileType, 'PNG')

t.end()
})
})

t.test('error', t => {
const exif = exec(['this_file_does_not_exist.png'])

exif.on('error', (error) => {
t.equal(error.message, 'File not found: this_file_does_not_exist.png')

t.end()
})
})

t.test('parse multiple exif data', t => {
const exif = exec(['-common', FIXTURE_DIR])

exif.on('exif', (exif) => {
t.equal(exif.length, 2)
t.equal(exif[0].FileName, 'placeholder.png')
t.equal(exif[1].FileName, 'subway.jpeg')

t.end()
})
})

t.test('stay open', t => {
const exif = open()
let len = 0

exif.send([join(FIXTURE_DIR, 'placeholder.png')])
exif.send([join(FIXTURE_DIR, 'placeholder.png')])
exif.send([join(FIXTURE_DIR, 'placeholder.png')])
exif.close()

exif.on('exif', (exif) => {
len++

t.equal(exif.length, 1)
t.equal(exif[0].FileType, 'PNG')

if (len === 3) {
t.end()
}
})
})

t.test('spawn sync', t => {
const exif = execSync(['-fast', join(FIXTURE_DIR, 'placeholder.png')])

t.equal(exif.length, 1)
t.equal(exif[0].FileType, 'PNG')
t.end()
})

t.test('spawn sync error', t => {
t.throws(
() => execSync(['this_file_does_not_exist.png']),
'File not found: this_file_does_not_exist.png'
)

t.end()
})
})

0 comments on commit 2a6b1e6

Please sign in to comment.