Add node modules and compiled JavaScript from main (#54)
Co-authored-by: Oliver King <oking3@uncc.edu>
This commit is contained in:
committed by
GitHub
parent
4a983766a0
commit
52d71d28bd
8
node_modules/stream-buffers/lib/constants.js
generated
vendored
Normal file
8
node_modules/stream-buffers/lib/constants.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
DEFAULT_INITIAL_SIZE: (8 * 1024),
|
||||
DEFAULT_INCREMENT_AMOUNT: (8 * 1024),
|
||||
DEFAULT_FREQUENCY: 1,
|
||||
DEFAULT_CHUNK_SIZE: 1024
|
||||
};
|
114
node_modules/stream-buffers/lib/readable_streambuffer.js
generated
vendored
Normal file
114
node_modules/stream-buffers/lib/readable_streambuffer.js
generated
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
'use strict';
|
||||
|
||||
var stream = require('stream');
|
||||
var constants = require('./constants');
|
||||
var util = require('util');
|
||||
|
||||
var ReadableStreamBuffer = module.exports = function(opts) {
|
||||
var that = this;
|
||||
opts = opts || {};
|
||||
|
||||
stream.Readable.call(this, opts);
|
||||
|
||||
this.stopped = false;
|
||||
|
||||
var frequency = opts.hasOwnProperty('frequency') ? opts.frequency : constants.DEFAULT_FREQUENCY;
|
||||
var chunkSize = opts.chunkSize || constants.DEFAULT_CHUNK_SIZE;
|
||||
var initialSize = opts.initialSize || constants.DEFAULT_INITIAL_SIZE;
|
||||
var incrementAmount = opts.incrementAmount || constants.DEFAULT_INCREMENT_AMOUNT;
|
||||
|
||||
var size = 0;
|
||||
var buffer = new Buffer(initialSize);
|
||||
var allowPush = false;
|
||||
|
||||
var sendData = function() {
|
||||
var amount = Math.min(chunkSize, size);
|
||||
var sendMore = false;
|
||||
|
||||
if (amount > 0) {
|
||||
var chunk = null;
|
||||
chunk = new Buffer(amount);
|
||||
buffer.copy(chunk, 0, 0, amount);
|
||||
|
||||
sendMore = that.push(chunk) !== false;
|
||||
allowPush = sendMore;
|
||||
|
||||
buffer.copy(buffer, 0, amount, size);
|
||||
size -= amount;
|
||||
}
|
||||
|
||||
if(size === 0 && that.stopped) {
|
||||
that.push(null);
|
||||
}
|
||||
|
||||
if (sendMore) {
|
||||
sendData.timeout = setTimeout(sendData, frequency);
|
||||
}
|
||||
else {
|
||||
sendData.timeout = null;
|
||||
}
|
||||
};
|
||||
|
||||
this.stop = function() {
|
||||
if (this.stopped) {
|
||||
throw new Error('stop() called on already stopped ReadableStreamBuffer');
|
||||
}
|
||||
this.stopped = true;
|
||||
|
||||
if (size === 0) {
|
||||
this.push(null);
|
||||
}
|
||||
};
|
||||
|
||||
this.size = function() {
|
||||
return size;
|
||||
};
|
||||
|
||||
this.maxSize = function() {
|
||||
return buffer.length;
|
||||
};
|
||||
|
||||
var increaseBufferIfNecessary = function(incomingDataSize) {
|
||||
if((buffer.length - size) < incomingDataSize) {
|
||||
var factor = Math.ceil((incomingDataSize - (buffer.length - size)) / incrementAmount);
|
||||
|
||||
var newBuffer = new Buffer(buffer.length + (incrementAmount * factor));
|
||||
buffer.copy(newBuffer, 0, 0, size);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
};
|
||||
|
||||
var kickSendDataTask = function () {
|
||||
if (!sendData.timeout && allowPush) {
|
||||
sendData.timeout = setTimeout(sendData, frequency);
|
||||
}
|
||||
}
|
||||
|
||||
this.put = function(data, encoding) {
|
||||
if (that.stopped) {
|
||||
throw new Error('Tried to write data to a stopped ReadableStreamBuffer');
|
||||
}
|
||||
|
||||
if(Buffer.isBuffer(data)) {
|
||||
increaseBufferIfNecessary(data.length);
|
||||
data.copy(buffer, size, 0);
|
||||
size += data.length;
|
||||
}
|
||||
else {
|
||||
data = data + '';
|
||||
var dataSizeInBytes = Buffer.byteLength(data);
|
||||
increaseBufferIfNecessary(dataSizeInBytes);
|
||||
buffer.write(data, size, encoding || 'utf8');
|
||||
size += dataSizeInBytes;
|
||||
}
|
||||
|
||||
kickSendDataTask();
|
||||
};
|
||||
|
||||
this._read = function() {
|
||||
allowPush = true;
|
||||
kickSendDataTask();
|
||||
};
|
||||
};
|
||||
|
||||
util.inherits(ReadableStreamBuffer, stream.Readable);
|
5
node_modules/stream-buffers/lib/streambuffer.js
generated
vendored
Normal file
5
node_modules/stream-buffers/lib/streambuffer.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./constants');
|
||||
module.exports.ReadableStreamBuffer = require('./readable_streambuffer');
|
||||
module.exports.WritableStreamBuffer = require('./writable_streambuffer');
|
72
node_modules/stream-buffers/lib/writable_streambuffer.js
generated
vendored
Normal file
72
node_modules/stream-buffers/lib/writable_streambuffer.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var stream = require('stream');
|
||||
var constants = require('./constants');
|
||||
|
||||
var WritableStreamBuffer = module.exports = function(opts) {
|
||||
opts = opts || {};
|
||||
opts.decodeStrings = true;
|
||||
|
||||
stream.Writable.call(this, opts);
|
||||
|
||||
var initialSize = opts.initialSize || constants.DEFAULT_INITIAL_SIZE;
|
||||
var incrementAmount = opts.incrementAmount || constants.DEFAULT_INCREMENT_AMOUNT;
|
||||
|
||||
var buffer = new Buffer(initialSize);
|
||||
var size = 0;
|
||||
|
||||
this.size = function() {
|
||||
return size;
|
||||
};
|
||||
|
||||
this.maxSize = function() {
|
||||
return buffer.length;
|
||||
};
|
||||
|
||||
this.getContents = function(length) {
|
||||
if(!size) return false;
|
||||
|
||||
var data = new Buffer(Math.min(length || size, size));
|
||||
buffer.copy(data, 0, 0, data.length);
|
||||
|
||||
if(data.length < size)
|
||||
buffer.copy(buffer, 0, data.length);
|
||||
|
||||
size -= data.length;
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
this.getContentsAsString = function(encoding, length) {
|
||||
if(!size) return false;
|
||||
|
||||
var data = buffer.toString(encoding || 'utf8', 0, Math.min(length || size, size));
|
||||
var dataLength = Buffer.byteLength(data);
|
||||
|
||||
if(dataLength < size)
|
||||
buffer.copy(buffer, 0, dataLength);
|
||||
|
||||
size -= dataLength;
|
||||
return data;
|
||||
};
|
||||
|
||||
var increaseBufferIfNecessary = function(incomingDataSize) {
|
||||
if((buffer.length - size) < incomingDataSize) {
|
||||
var factor = Math.ceil((incomingDataSize - (buffer.length - size)) / incrementAmount);
|
||||
|
||||
var newBuffer = new Buffer(buffer.length + (incrementAmount * factor));
|
||||
buffer.copy(newBuffer, 0, 0, size);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
};
|
||||
|
||||
this._write = function(chunk, encoding, callback) {
|
||||
increaseBufferIfNecessary(chunk.length);
|
||||
chunk.copy(buffer, size, 0);
|
||||
size += chunk.length;
|
||||
callback();
|
||||
};
|
||||
};
|
||||
|
||||
util.inherits(WritableStreamBuffer, stream.Writable);
|
Reference in New Issue
Block a user