Skip to content

Commit 4014a50

Browse files
committed
Initial commit
0 parents  commit 4014a50

30 files changed

+1076
-0
lines changed

.eslintrc

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
env:
2+
node: true
3+
browser: false
4+
5+
plugins:
6+
- nodeca
7+
8+
rules:
9+
block-scoped-var: 2
10+
brace-style: [ 2, '1tbs', { "allowSingleLine": true } ]
11+
comma-dangle: 2
12+
comma-spacing: 2
13+
comma-style: 2
14+
consistent-return: 2
15+
consistent-this: [ 2, self ]
16+
curly: [ 2, all ]
17+
# default-case: 2
18+
# dot-notation: [ 2, { allowKeywords: true } ]
19+
eol-last: 2
20+
eqeqeq: 2
21+
func-style: [ 2, declaration ]
22+
handle-callback-err: 2
23+
# key-spacing: [ 2, { "align": "value" } ]
24+
max-depth: [ 1, 6 ]
25+
max-nested-callbacks: [ 1, 8 ]
26+
# string can exceed 80 chars, but should not overflow github website :)
27+
max-len: [ 2, 120, 1000 ]
28+
new-cap: 2
29+
new-parens: 2
30+
no-alert: 2
31+
no-array-constructor: 2
32+
no-bitwise: 2
33+
no-caller: 2
34+
no-catch-shadow: 2
35+
no-cond-assign: 2
36+
no-console: 1
37+
no-constant-condition: 2
38+
no-control-regex: 2
39+
no-div-regex: 2
40+
no-dupe-args: 2
41+
no-dupe-keys: 2
42+
no-duplicate-case: 2
43+
no-else-return: 2
44+
# no-empty: 1
45+
no-empty-class: 2
46+
no-empty-label: 2
47+
no-eq-null: 2
48+
no-eval: 2
49+
no-ex-assign: 2
50+
no-extend-native: 2
51+
no-extra-bind: 2
52+
no-extra-boolean-cast: 2
53+
no-extra-semi: 2
54+
no-fallthrough: 2
55+
no-floating-decimal: 2
56+
no-func-assign: 2
57+
no-implied-eval: 2
58+
no-inner-declarations: 2
59+
no-invalid-regexp: 2
60+
no-irregular-whitespace: 2
61+
no-iterator: 2
62+
no-label-var: 2
63+
no-lone-blocks: 1
64+
no-lonely-if: 2
65+
no-loop-func: 2
66+
no-mixed-spaces-and-tabs: 2
67+
no-native-reassign: 2
68+
no-negated-in-lhs: 2
69+
no-new: 2
70+
no-new-func: 2
71+
no-new-object: 2
72+
no-new-require: 2
73+
no-new-wrappers: 2
74+
no-obj-calls: 2
75+
no-octal: 2
76+
no-octal-escape: 2
77+
no-proto: 2
78+
no-redeclare: 2
79+
# no-regex-spaces: 2
80+
no-reserved-keys: 2
81+
no-return-assign: 2
82+
no-self-compare: 2
83+
no-sequences: 2
84+
# no-shadow: 2
85+
no-shadow-restricted-names: 2
86+
no-sparse-arrays: 2
87+
no-path-concat: 2
88+
no-throw-literal: 2
89+
no-trailing-spaces: 2
90+
no-undef: 2
91+
no-undef-init: 2
92+
no-undefined: 2
93+
no-unreachable: 2
94+
no-unused-expressions: 2
95+
no-use-before-define: 2
96+
operator-assignment: 1
97+
semi: 2
98+
semi-spacing: 2
99+
space-after-keywords: 2
100+
space-before-blocks: 2
101+
space-before-function-paren: [ 2, { "anonymous": "always", "named": "never" } ]
102+
space-in-brackets: [ 2, always, { propertyName: false } ]
103+
space-in-parens: [ 2, never ]
104+
space-infix-ops: 2
105+
space-return-throw-case: 2
106+
space-unary-ops: 2
107+
spaced-line-comment: [ 1, always, { exceptions: [ '/', '=' ] } ]
108+
strict: [ 2, global ]
109+
quotes: [ 2, single, avoid-escape ]
110+
quote-props: [ 1, 'as-needed' ]
111+
radix: 2
112+
use-isnan: 2
113+
valid-typeof: 2
114+
yoda: [ 2, never, { "exceptRange": true } ]
115+
116+
117+
118+
#
119+
# Our custom rules from plugin
120+
#
121+
nodeca/no-lodash-aliases: 2
122+
nodeca/no-async-aliases: 2
123+
nodeca/indent: [2, spaces, 2]
124+
nodeca/no-wire-anonymous: 1

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
doc
3+
*.log
4+
*.swp

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- '0.10'
4+
- '0.12'
5+
- '4'
6+
sudo: false

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2015 Vitaly Puzrin.
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

Makefile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
PATH := ./node_modules/.bin:${PATH}
2+
3+
NPM_PACKAGE := $(shell node -e 'console.log(require("./package.json").name)')
4+
NPM_VERSION := $(shell node -e 'console.log(require("./package.json").version)')
5+
6+
TMP_PATH := /tmp/${NPM_PACKAGE}-$(shell date +%s)
7+
8+
REMOTE_NAME ?= origin
9+
REMOTE_REPO ?= $(shell git config --get remote.${REMOTE_NAME}.url)
10+
11+
CURR_HEAD := $(firstword $(shell git show-ref --hash HEAD | cut -b -6) master)
12+
GITHUB_PROJ := nodeca/${NPM_PACKAGE}
13+
14+
15+
help:
16+
echo "make help - Print this help"
17+
echo "make lint - Lint sources with JSHint"
18+
echo "make test - Lint sources and run all tests"
19+
echo "make publish - Set new version tag and publish npm package"
20+
21+
22+
lint:
23+
eslint --reset .
24+
25+
26+
test: lint
27+
mocha
28+
29+
test-all: lint
30+
LINKS_CHECK=all mocha
31+
32+
33+
publish:
34+
@if test 0 -ne `git status --porcelain | wc -l` ; then \
35+
echo "Unclean working tree. Commit or stash changes first." >&2 ; \
36+
exit 128 ; \
37+
fi
38+
@if test 0 -ne `git fetch ; git status | grep '^# Your branch' | wc -l` ; then \
39+
echo "Local/Remote history differs. Please push/pull changes." >&2 ; \
40+
exit 128 ; \
41+
fi
42+
@if test 0 -ne `git tag -l ${NPM_VERSION} | wc -l` ; then \
43+
echo "Tag ${NPM_VERSION} exists. Update package.json" >&2 ; \
44+
exit 128 ; \
45+
fi
46+
git tag ${NPM_VERSION} && git push origin ${NPM_VERSION}
47+
npm publish https://github.com/${GITHUB_PROJ}/tarball/${NPM_VERSION}
48+
49+
50+
.PHONY: publish lint test
51+
.SILENT: help lint test

README.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
probe-image-size
2+
================
3+
4+
[![Build Status](https://img.shields.io/travis/nodeca/probe-image-size/master.svg?style=flat)](https://travis-ci.org/nodeca/probe-image-size)
5+
[![NPM version](https://img.shields.io/npm/v/probe-image-size.svg?style=flat)](https://www.npmjs.org/package/probe-image-size)
6+
7+
8+
> Get image size without full download
9+
10+
Supported image types: JPG, GIF, PNG, BMP.
11+
12+
13+
Install
14+
-------
15+
16+
```bash
17+
npm install probe-image-size --save
18+
```
19+
20+
Example
21+
-------
22+
23+
```js
24+
var probe = require('probe-image-size');
25+
26+
// Get by URL
27+
//
28+
probe('http://example.com/image.jpg', function (err, result) {
29+
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpg' }
30+
});
31+
32+
// By URL with options
33+
//
34+
probe({ url: 'http://example.com/image.jpg', timeout: 5000 }, function (err, result) {
35+
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpg' }
36+
});
37+
38+
// From stream
39+
//
40+
var input = require('fs').createReadStream('image.jpg');
41+
42+
probe(input, function (err, result) {
43+
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpg' }
44+
45+
// terminate input, depends on stream type,
46+
// this example is for fs streams only.
47+
input.destroy();
48+
});
49+
```
50+
51+
52+
API
53+
---
54+
55+
### probe(src, callback(err, result))
56+
57+
`src` can be of this types:
58+
59+
- __String__ - URL to fetch
60+
- __Object__ - options for [request](https://github.com/request/request)
61+
- __Stream__ - readable stream
62+
63+
`result` contains:
64+
65+
```js
66+
{
67+
width: XX,
68+
height: YY,
69+
type: ..., // image type
70+
mime: ... // mime type
71+
}
72+
```
73+
74+
`err` is extended with `status` field on bad server response.
75+
76+
__Note.__ If you use stream as source, it's your responsibility to terminate
77+
reading in callback. That will release resources as soon as possible. On
78+
http requests that's done automatically.
79+
80+
81+
Similar projects
82+
----------------
83+
84+
- [image-size](https://github.com/netroy/image-size)
85+
- [imagesize](https://github.com/arnaud-lb/imagesize.js)
86+
87+
88+
License
89+
-------
90+
91+
[MIT](https://raw.github.com/nodeca/probe-image-size/master/LICENSE)

index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
4+
module.exports = require('./lib');

lib/common.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
4+
var Transform = require('stream').Transform;
5+
var streamParser = require('stream-parser');
6+
var inherits = require('util').inherits;
7+
8+
9+
function ParserStream() {
10+
Transform.call(this);
11+
}
12+
13+
inherits(ParserStream, Transform);
14+
streamParser(ParserStream.prototype);
15+
16+
17+
exports.ParserStream = ParserStream;
18+
19+
exports.once = function (fn) {
20+
var called = false;
21+
22+
return function () {
23+
if (!called) {
24+
called = true;
25+
fn.apply(this, arguments);
26+
}
27+
};
28+
};

0 commit comments

Comments
 (0)