lightstreamer-adapter
Version:
This package includes the resources needed to write Data Adapters and Metadata Adapters for Lightstreamer Server in a Node.js environment. The adapters will run in a separate process, communicating with the Server through the Adapter Remoting Infrastructu
86 lines (67 loc) • 1.72 kB
JavaScript
/*
Copyright (c) Lightstreamer Srl
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* Module import
*
*/
var Stream = require('stream').Stream,
EventEmitter = require('events').EventEmitter;
/**
* Fake synchronous stream
*
*/
function TestStream() {
var that, data = new Array();
/**
* Fake synchronous stream
*
*/
function setEncoding(encoding) {
// NOP
}
function write(chunk, encoding) {
data.push(chunk);
}
function destroy(error) {
that.emit('error', error);
}
function pushTestData(chunk) {
that.emit('data', chunk);
}
function popTestData() {
return data.shift();
}
function dumpTestData() {
console.log("Test data:");
for (var i = 0; i < data.length; i++) {
console.log(data[i]);
}
console.log("----------------------");
}
function getTestData() {
return data;
}
that = {
write: write,
destroy: destroy,
pushTestData: pushTestData,
popTestData: popTestData,
getTestData: getTestData,
setEncoding: setEncoding,
dumpTestData: dumpTestData
};
that.__proto__ = Stream.prototype;
that.writable = true;
return that;
}
exports.TestStream = TestStream;