Permalink
Browse files

Enable resolvers only if node version >=0.7.0

  • Loading branch information...
nikhilm committed Jun 8, 2012
1 parent bd3b654 commit a89d79fc19c557a937ab211e24f937b9f3ed9855
Showing with 18 additions and 2 deletions.
  1. +4 −0 spec/resolverSpec.js
  2. +4 −0 src/taglib.cc
  3. +10 −2 src/taglib.h
View
@@ -3,6 +3,8 @@ var assert = require('assert'),
fs = require('fs'),
Taglib = require(__dirname + '/../taglib');
+if (Taglib.addResolvers) {
+
Taglib.addResolvers(function(fn) {
var data = fs.readFileSync(fn, 'ascii');
if (data.substring(0, 3) == 'ID3')
@@ -231,3 +233,5 @@ vows.describe('taglib bindings: Dumb mp3 Resolver')
}
}
}).export(module);
+
+}
View
@@ -284,6 +284,7 @@ TagLib::String NodeStringToTagLibString( Local<Value> s )
}
}
+#ifdef ENABLE_RESOLVERS
Handle<Value> AddResolvers(const Arguments &args)
{
for (int i = 0; i < args.Length(); i++) {
@@ -364,6 +365,7 @@ TagLib::File *CallbackResolver::createFile(TagLib::FileName fileName, bool readA
return node_taglib::createFile(stream, baton.type);
}
+#endif // ENABLE_RESOLVERS
}
extern "C" {
@@ -386,7 +388,9 @@ init (Handle<Object> target)
#endif
NODE_SET_METHOD(target, "read", AsyncReadFile);
+#ifdef ENABLE_RESOLVERS
NODE_SET_METHOD(target, "addResolvers", AddResolvers);
+#endif
Tag::Initialize(target);
}
View
@@ -7,6 +7,12 @@
#include <uv.h>
#include <sys/time.h>
+#include <node_version.h>
+
+#if NODE_VERSION_AT_LEAST(0, 7, 0)
+#define ENABLE_RESOLVERS
+#endif
+
namespace node_taglib {
class Tag;
class BufferStream;
@@ -21,8 +27,6 @@ static TagLib::File *createFile(TagLib::IOStream *stream, TagLib::String format)
v8::Handle<v8::String> ErrorToString(int error);
v8::Handle<v8::Value> TagLibStringToString( TagLib::String s );
TagLib::String NodeStringToTagLibString( v8::Local<v8::Value> s );
-v8::Handle<v8::Value> AddResolvers(const v8::Arguments &args);
-
v8::Handle<v8::Value> AsyncReadFile(const v8::Arguments &args);
void AsyncReadFileDo(uv_work_t *req);
void AsyncReadFileAfter(uv_work_t *req);
@@ -43,6 +47,9 @@ struct AsyncBaton {
Tag *tag; /* only used by taglib.tag */
};
+#ifdef ENABLE_RESOLVERS
+v8::Handle<v8::Value> AddResolvers(const v8::Arguments &args);
+
class CallbackResolver;
struct AsyncResolverBaton {
@@ -63,6 +70,7 @@ class CallbackResolver : public TagLib::FileRef::FileTypeResolver {
static void invokeResolverCb(uv_async_t *handle, int status);
static void invokeResolver(AsyncResolverBaton *baton);
};
+#endif
}
#endif

0 comments on commit a89d79f

Please sign in to comment.