Permalink
Browse files

v0.2

  • Loading branch information...
SaltwaterC committed Aug 11, 2011
1 parent 23dc573 commit b94313974f3ec89b5298d547b437311c34bd2e62
Showing with 65 additions and 20 deletions.
  1. +5 −2 .gitignore
  2. +5 −0 .npmignore
  3. +3 −0 CHANGELOG.md
  4. +10 −2 Makefile
  5. +3 −3 README.md
  6. BIN arc/file-5.07.tar.gz
  7. +7 −11 lib/mime-magic.js
  8. +6 −2 package.json
  9. +26 −0 tools/build.sh
View
@@ -1,2 +1,5 @@
-/.project
-/.settings
+.project
+.settings/
+src/
+bin/
+share/
View
@@ -0,0 +1,5 @@
+.project
+.settings/
+src/
+bin/
+share/
View
@@ -1,3 +1,6 @@
+## v0.2
+ * Includes the file(1) (v5.07) source tree along with a build script which was made to work on Ubuntu / OS X. The wrapper uses this file version along with the appropriate magic database.
+
## v0.1.1
* Updated the error detection code. Some file 4.x/5.x versions used to send the error message via STDOUT. The recent versions fix this behavior by sending the error message via STDERR. mime-magic error reporting is compatible with both.
View
@@ -1,5 +1,13 @@
-all:
+npm:
/usr/bin/env npm install
-publish: all
+publish: npm
/usr/bin/env npm publish
+
+build:
+ tools/build.sh
+
+purge:
+ rm -rf src/
+ rm -rf bin/
+ rm -rf share/
View
@@ -24,8 +24,8 @@ mime.fileWrapper('/path/to/foo.pdf', function (err, mime) {
});
```
-Passing relative paths is supported. The fileWrapper uses child_process.exec behind the scenes, therefore the err argument contains the information returned by the exec method itself plus the error message returned by file(1). The module was developed against file 5.03 which sends the error message via STDOUT. An unfortunate choice from the developer, but if your file utility behaves differently, then you may not get the exact error message.
+Passing relative paths is supported. The fileWrapper uses child_process.exec behind the scenes, therefore the err argument contains the information returned by the exec method itself plus the error message returned by file(1).
-## Known issues
+## Notice
-Not all the unices are supported by this release. The file(1) invocation is different on OS X for example. Other possible (such as BSD ports) use cases are unknown. Till a proper wrapper and proper bindings are available, consider it usable just under the above circumstances.
+The module was developed under Ubuntu 10.04. It was tested under OS X Snow Leopard. Other platforms may be supported, but the behavior is untested.
View
Binary file not shown.
View
@@ -1,24 +1,20 @@
var p = require('path');
var cp = require('child_process');
+var fileExec = p.resolve(__dirname + '/../bin/file') + ' --magic-file ' + p.resolve(__dirname + '/../share/magic.mgc') + ' --brief --mime-type ';
+
var trim = function (string) {
string = string || '';
- return string.replace(/^\s*/, '').replace(/\s*$/, '');
+ return string.trim();
};
var fileWrapper = function (path, cb) {
- path = p.resolve(path);
- cp.exec('/usr/bin/env file --brief --mime-type ' + path, function (err, stdout, stderr) {
- stdout = trim(stdout);
- stderr = trim(stderr);
+ cp.exec(fileExec + p.resolve(path), function (err, stdout) {
+ stdout = stdout.trim();
if (err) {
- var message = '';
- if (stderr) {
- message = stderr;
- } else if (stdout) { // some version send the error over STDOUT
- message = stdout;
+ if (stdout) {
+ err.message = stdout;
}
- err.message = message;
cb(err);
} else {
cb(null, stdout);
View
@@ -1,6 +1,6 @@
{
"name": "mime-magic",
- "version": "0.1.1",
+ "version": "0.2.0",
"main": "./lib/mime-magic.js",
"description": "libmagic bindings for node.js. Includes a file(1) wrapper as alternative.",
"engines": {
@@ -15,5 +15,9 @@
"type": "git",
"url": "git://github.com/SaltwaterC/mime-magic.git"
},
- "keywords": ["mime", "magic", "libmagic", "file", "wrapper"]
+ "keywords": ["mime", "magic", "libmagic", "file", "wrapper"],
+ "scripts": {
+ "preinstall": "make build",
+ "preuninstall": "make purge"
+ }
}
View
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+if [ ! -d src/file-5.07 ]
+then
+ cd arc
+ tar -xf file-5.07.tar.gz
+ mkdir ../src
+ mv file-5.07 ../src
+ cd ..
+fi
+
+if [ ! -f share/magic.mgc -o ! -f bin/file ]
+then
+ cd src/file-5.07
+ ./configure
+ make
+ cd ../../
+ mkdir -p share
+ cp src/file-5.07/magic/magic.mgc share
+ mkdir -p bin/.libs
+ ./src/file-5.07/src/file -v
+ cp src/file-5.07/src/file bin/file
+ cp src/file-5.07/src/.libs/file bin/.libs
+fi
+
+exit 0

0 comments on commit b943139

Please sign in to comment.