Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.slice is not a function #6

Closed
grzegorzbernat opened this issue Jul 26, 2017 · 3 comments
Closed

.slice is not a function #6

grzegorzbernat opened this issue Jul 26, 2017 · 3 comments

Comments

@grzegorzbernat
Copy link

I have got problem similiar to issue#4. I have now newest version of Node.JS (v.8.2.1) and I am running everything on Linux.
When I was trying to run of examples (readTag.js) from this library (and also mifare-classic examples) I got error:
`WARNING: End of message does not look correct. Expecting 0xFE but got 110
<Buffer d1 01 08 54 02 65 6e 48 65 6c 6c 6f>
/home/pi/magisterka/ndef-js/lib/ndef.js:276
var bytes = bytes.slice(0), // clone since parsing is destructive
^

TypeError: bytes.slice is not a function
at Object.decodeMessage (/home/pi/magisterka/ndef-js/lib/ndef.js:276:27)
at printNdefInfo (/home/pi/magisterka/ndef-js/examples/readTag.js:16:20)
at ChildProcess. (/home/pi/magisterka/ndef-js/examples/readTag.js:53:9)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at maybeClose (internal/child_process.js:921:16)
at Socket.stream.socket.on (internal/child_process.js:348:11)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at Pipe._handle.close [as _onclose] (net.js:549:12)
`

I dont know what should I change to support this version of Node?

@don
Copy link
Owner

don commented Jul 26, 2017

decodeMessage is expecting an array of bytes, which should have a slice function. If you're passing in a Uint8Array or Buffer it'll probably fail.

@grzegorzbernat
Copy link
Author

I tried to run readTag example from this library as is. But it failed.

var spawn = require('child_process').spawn,
    ndef = require('../index'),
    fs = require('fs'),
    mifareClassic = require('../lib/mifare-classic'),
    fileName = 'foo.mfd';
        
function printNdefInfo() {
    buffer = fs.readFileSync(fileName);
    ndefBuffer = mifareClassic.getNdefData(buffer);
    console.log(ndefBuffer);

    message = ndef.decodeMessage(ndefBuffer.toJSON());
    console.log(message);

(...)

When I have modified this example and I passed data to decoding, it worked.
message = ndef.decodeMessage(ndefBuffer.toJSON().data);

But I think there is some problem with library and/or Node.JS version because in raw version of examples were errors.

@don
Copy link
Owner

don commented May 11, 2018

@greggyPL message = ndef.decodeMessage(ndefBuffer.toJSON().data); works because the original code was written for Node v0.8. Node v0.10 changed the JSON for Buffer. I modified ndef.decodeMessage to take a Buffer so this is unnecessary.

@don don closed this as completed May 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants