node-qrcode-lite/lib/core/byte-data.js
Vincenzo Greco 77064f5e5e Refactor/core ()
* Split core lib into multiple files

* Refactor data encoding methods

* Refactor data masking process

* Improve qr code generation process

* Increase minimum required node version to 0.10

* Add linter

* Add tests and tests coverage

* Update travis config to fix compilation issues

* Add examples folder

* Add missing license tag in package.json

* Update build script and add sourcemap support

* Publish only strictly needed files on npm

* Update readme
2016-12-16 23:45:08 +01:00

40 lines
848 B
JavaScript

var Buffer = require('../utils/buffer')
var Mode = require('./mode')
function ByteData (data) {
this.mode = Mode.BYTE
this.data = new Buffer(data)
}
ByteData.getCharCountIndicator = function getCharCountIndicator (version) {
if (version >= 1 && version < 10) {
// 1 - 9
return 8
} else if (version >= 10 && version < 41) {
// 10 - 40
return 16
} else {
throw new Error('version: ' + version)
}
}
ByteData.prototype = {
getLength: function (buffer) {
return this.data.length
},
append: function (data) {
this.data = Buffer.concat([this.data, new Buffer(data)])
return this
},
write: function (buffer) {
for (var i = 0, l = this.data.length; i < l; i++) {
buffer.put(this.data[i], 8)
}
},
getCharCountIndicator: ByteData.getCharCountIndicator
}
module.exports = ByteData