Skip to content

Commit

Permalink
CI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasher committed Mar 5, 2018
1 parent 3a42d08 commit aea4cf3
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ Examples

var magic = new Magic();

magic.compile("node_modules/mmmagic/test/dummy_magic_file", function(err, result) {
magic.compile("node_modules/mmmagic/test/dummy_magic_file;node_modules/mmmagic/test/dummy_magic_file2", function(err, result) {
if (err) throw err;
console.log("Compiled magic file successfully. Compile file name: ", result);
// output: Compiled magic file successfully. Compile file name: [ 'dummy_magic_file.mgc' ]
@@ -122,4 +122,4 @@ Magic methods

* **detect**(< _Buffer_ >data, < _Function_ >callback) - _(void)_ - Inspects the contents of data. The callback receives two arguments: an < _Error_ > object in case of error (null otherwise), and a < _String_ > containing the result of the inspection.

* **compile**(< _String_ >path, < _Function_ >callback) - _(void)_ - Compile a colon separated list of database files. The compiled files can be used later on with one of the other methods. The callback receives two arguments: an < _Error_ > object in case of error (null otherwise), and an array of < _String_ > containing the names of the compiled files.
* **compile**(< _String_ >path, < _Function_ >callback) - _(void)_ - Compile a semicolon separated list of database files. The compiled files can be used later on with one of the other methods. The callback receives two arguments: an < _Error_ > object in case of error (null otherwise), and an array of < _String_ > containing the names of the compiled files.
17 changes: 14 additions & 3 deletions src/binding.cc
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
#include <nan.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>

#ifdef _WIN32
# include <io.h>
@@ -434,13 +435,23 @@ class Magic : public ObjectWrap {
// Creating the list of the compiled magic files
Local<Array> results = Nan::New<Array>();
uint32_t i = 0;
char *file_path = strtok(baton->data, ":");
char *file_path = strtok(baton->data, ";");

while(file_path != NULL)
{
// Getting the file name from the source
const char* file_path_dup = strdup(file_path);
const char* file_name = basename(file_path_dup);
const char* file_name;
#ifdef _WIN32
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath_s(file_path_dup, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT);
file_name = fname;
#else
file_name = basename(file_path_dup);
#endif

// Creating the name of the mgc file (which is the magic file name + ".mgc")
size_t file_name_length = strlen(file_name);
@@ -460,7 +471,7 @@ class Magic : public ObjectWrap {
delete[] mgc_file_name;

// Looking for the next file name
file_path=strtok(NULL, ":");
file_path=strtok(NULL, ";");
}

argv[1] = Local<Value>(results);
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ var tests = [
{ run: function() {
var dummy_magic_file = path.join(__dirname, 'dummy_magic_file');
var dummy_magic_file2 = dummy_magic_file + "2";
var colon_seperated_magic_files = dummy_magic_file + ":" + dummy_magic_file2;
var colon_seperated_magic_files = dummy_magic_file + ";" + dummy_magic_file2;
var magic = new mmm.Magic(mmm.MAGIC_MIME_TYPE);
magic.compile(colon_seperated_magic_files, function(err, result) {
assert.strictEqual(err, null);

0 comments on commit aea4cf3

Please sign in to comment.