1 (edited by jhomer 2014-06-06 20:07:10)

Topic: Node.js Addons - Exporting Binary Data

Have the start of simple node.js Addon Library for libnfc and libfreefare. 

Doing well and have solved most of the problems.  However I am stuck with trying to get binary data out of node.js back to Javascript.  Here is my code so far:

Handle<Value> getMifareData(const Arguments& args) {
  HandleScope scope;

  if (mad != NULL)
  {
    uint8_t buffer[4096];
      ssize_t len;

    if ((len = mifare_application_read (tags[tagIndex], mad, mad_nfcforum_aid,
                                      buffer, sizeof(buffer),
                                      mifare_classic_nfcforum_public_key_a, MFC_KEY_A)) != -1)
    {
            v8::Handle<v8::Object> external_array = v8::Object::New();
            external_array->SetIndexedPropertiesToExternalArrayData(buffer, v8::kExternalUnsignedByteArray, len);
            return scope.Close(external_array);
    }
    else
    {
        // Something went wrong!
        return scope.Close(Undefined());
    }
  }
  else
  {
    // Something Went Wrong - No MAD
    return scope.Close(Undefined());
  }
}

This works.  However it sends the results back as a Java Object and not an array making reading and processing it difficult.  Anyone in the community know how to write this better?

When library gets some stability will be releasing to public open source so worth helping me!

Thanks
Jon