.slice is not a function
grzegorzbernat opened this issue · 3 comments
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?
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.
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.
@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.