json-stream-wrapper
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -7,68 +7,2 @@ 'use strict'; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _stream = require('stream'); | ||
var Base64Stream = (function (_Transform) { | ||
_inherits(Base64Stream, _Transform); | ||
function Base64Stream() { | ||
_classCallCheck(this, Base64Stream); | ||
_get(Object.getPrototypeOf(Base64Stream.prototype), 'constructor', this).apply(this, arguments); | ||
} | ||
_createClass(Base64Stream, [{ | ||
key: '_transform', | ||
value: function _transform(chunk, encoding, cb) { | ||
var baseStr = chunk; | ||
if (this.extra) { | ||
baseStr = Buffer.concat([this.extra, baseStr]); | ||
this.extra = null; | ||
} | ||
// 3 bytes are represented by 4 characters, so we can only encode in groups of 3 bytes | ||
var remaining = baseStr.length % 3; | ||
if (remaining !== 0) { | ||
// Store the extra bytes for later | ||
this.extra = baseStr.slice(baseStr.length - remaining); | ||
baseStr = baseStr.slice(0, baseStr.length - remaining); | ||
} | ||
// Convert chunk to a base 64 string | ||
baseStr = baseStr.toString('base64'); | ||
// Push the chunk | ||
this.push(baseStr); | ||
cb(); | ||
} | ||
}, { | ||
key: '_flush', | ||
value: function _flush(cb) { | ||
if (this.extra) { | ||
this.push(this.extra.toString('base64')); | ||
} | ||
cb(); | ||
} | ||
}]); | ||
return Base64Stream; | ||
})(_stream.Transform); | ||
exports['default'] = Base64Stream; | ||
module.exports = exports['default']; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
@@ -85,56 +19,2 @@ | ||
exports['default'] = _jsonStreamWrapper2['default']; | ||
exports.Base64Stream = _base64Stream2['default']; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _stream = require('stream'); | ||
var JsonStreamWrapper = (function (_Transform) { | ||
_inherits(JsonStreamWrapper, _Transform); | ||
function JsonStreamWrapper(jsonData, streamDataAttribute) { | ||
_classCallCheck(this, JsonStreamWrapper); | ||
_get(Object.getPrototypeOf(JsonStreamWrapper.prototype), 'constructor', this).call(this); | ||
this.streamDataAttribute = streamDataAttribute; | ||
this.jsonData = jsonData; | ||
this.firstCall = true; | ||
} | ||
_createClass(JsonStreamWrapper, [{ | ||
key: '_transform', | ||
value: function _transform(chunk, encoding, done) { | ||
if (this.firstCall) { | ||
this.push(JSON.stringify(this.jsonData).slice(0, -1) + (',"' + this.streamDataAttribute + '":"'), 'utf8'); | ||
this.firstCall = false; | ||
} | ||
this.push(chunk, 'utf8'); | ||
done(); | ||
} | ||
}, { | ||
key: '_flush', | ||
value: function _flush(done) { | ||
this.push('"}', 'utf8'); | ||
done(); | ||
} | ||
}]); | ||
return JsonStreamWrapper; | ||
})(_stream.Transform); | ||
exports['default'] = function (jsonData, streamDataAttribute) { | ||
return new JsonStreamWrapper(jsonData, streamDataAttribute); | ||
}; | ||
module.exports = exports['default']; | ||
exports.Base64Stream = _base64Stream2['default']; |
{ | ||
"name": "json-stream-wrapper", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A stream wrapper which wraps a stream into a JSON object", | ||
@@ -11,4 +11,4 @@ "main": "dist/index.js", | ||
"test:coverage": "istanbul cover _mocha -x -- --compilers js:babel/register --reporter dot --recursive -r setup-referee-sinon/globals test/unit", | ||
"build": "rimraf dist && mkdir dist && babel src/*.js -o dist/index.js", | ||
"prepublish": "npm run build" | ||
"build": "rimraf dist && mkdir dist && babel -d dist/ src/", | ||
"prepublish": "npm run test && npm run build" | ||
}, | ||
@@ -15,0 +15,0 @@ "contributors": [ |
Sorry, the diff of this file is not supported yet
22209
16
223