How to use memorystream - 10 common examples

To help you get started, we’ve selected a few memorystream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github acarl / pg-restify / test / helper.js View on Github external
exports.fullServerPath = 'http://localhost:' + exports.serverPort;

exports.request = request(exports.fullServerPath);


//TODO:parameterize the connection string and server port
exports.pgConfig = {
  connectionString: 'pg://postgres@localhost/pg_restify'
};
exports.invalidpgConfig = {
  connectionString: 'pg://postgres@localhost/pg_restify_invalid'
};

exports.pgRestifyInstance = null;

exports.logWriter = MemoryStream.createWriteStream();


exports.initDefaultServer = function(next) {

  if (exports.pgRestifyInstance) {
    // if already initialize just return the cached instance
    return next(null, exports.pgRestifyInstance);
  }

  var log = bunyan.createLogger({
    name: 'node-rest-api',
    stream: exports.logWriter,// comment out this line for errors to log to the console
    level: 'error'
  });

  var server = restify.createServer({log:log});
github qmit-pro / moleculer-api / src / examples / moleculer / index.ts View on Github external
if (this.lastPacketTime && new Date().getTime() - this.lastPacketTime > 1000 * 5) {
                  // @ts-ignore
                  stream.destroy();
                  clearInterval(this.interval);
                  delete this.interval;
                  console.log("server stream closed due to interval timeout 5s", id);
                }
              }, 1000);
              console.log("server stream created", id);
            } else {
              if (!this.serverStream) {
                throw new Error("there are no server going on");
              }

              // new stream for client
              const stream = new MemoryStream();
              console.log("client stream created", id);
              if (this.metaChunks) {
                console.log(`send meta chunks (${this.metaChunks.length}) to ${id}`);
                for (const chunk of this.metaChunks) {
                  stream.write(chunk);
                }
              }
              stream.on("close", () => {
                const index = (this.clientStreams as MemoryStream[]).indexOf(stream);
                if (index !== -1) {
                  this.clientStreams.splice(index, 1);
                  console.log("client stream closed", id);
                }
              });
              this.clientStreams.push(stream);
github qmit-pro / moleculer-api / src / gateway.dev.ts View on Github external
if (this.lastPacketTime && new Date().getTime() - this.lastPacketTime > 1000 * 5) {
                  // @ts-ignore
                  stream.destroy();
                  clearInterval(this.interval);
                  delete this.interval;
                  console.log("server stream closed due to interval timeout 5s", id);
                }
              }, 1000);
              console.log("server stream created", id);
            } else {
              if (!this.serverStream) {
                throw new Error("there are no server going on");
              }

              // new stream for client
              const stream = new MemoryStream();
              console.log("client stream created", id);
              if (this.metaChunks) {
                console.log(`send meta chunks (${this.metaChunks.length}) to ${id}`);
                for (const chunk of this.metaChunks) {
                  stream.write(chunk);
                }
              }
              stream.on("close", () => {
                const index = (this.clientStreams as MemoryStream[]).indexOf(stream);
                if (index !== -1) {
                  this.clientStreams.splice(index, 1);
                  console.log("client stream closed", id);
                }
              });
              this.clientStreams.push(stream);
github qmit-pro / moleculer-api / src / examples / moleculer / index.ts View on Github external
handler(ctx) {
            // bidirectional
            const serverStream = new MemoryStream("---initial-content-from-server---");
            const clientStream = ctx.params! as ReadableStream;
            clientStream.on("data", data => {
              serverStream.write("---remote service received data and echo: " + data.toString() + "---");
            });
            return serverStream;
          },
        },
github qmit-pro / moleculer-api / src / gateway.dev.ts View on Github external
handler(ctx) {
            // bidirectional
            const serverStream = new MemoryStream("---initial-content-from-server---");
            const clientStream = ctx.params! as ReadableStream;
            clientStream.on("data", data => {
              serverStream.write("---remote service received data and echo: " + data.toString() + "---");
            });
            return serverStream;
          },
        },
github tidepool-org / viz / test / helpers / pdfDoc.js View on Github external
constructor(opts = {}) {
    this.stream = new MemoryStream();
    this.stream.toBlobURL = () => this.pdf.url;
    this.stream.toBlob = () => this.pdf.blob;

    this.autoFirstPage = false;
    this.bufferPages = true;
    this.margin = opts.margin;

    this.page = {
      width: 300,
      margins: {
        left: 36,
        right: 36,
        top: 36,
        bottom: 36,
      },
    };
github iamolegga / nestjs-pino / src / index.spec.ts View on Github external
it(loggerMethodName, async () => {
          const stream = new MemoryStream();
          const serviceLogMessage = Math.random().toString();
          const outOfContextLogMessage = Math.random().toString();
          let logs = "";

          stream.on("data", (chunk: string) => {
            logs += chunk.toString();
          });

          @Injectable()
          class TestService {
            constructor(private readonly logger: Logger) {}
            someMethod() {
              this.logger[loggerMethodName](serviceLogMessage);
            }
          }
github iamolegga / nestjs-pino / src / index.spec.ts View on Github external
it("should be used", async () => {
        const stream = new MemoryStream();
        const random = Math.random().toString();
        let logs = "";

        stream.on("data", (chunk: string) => {
          logs += chunk.toString();
        });

        @Injectable()
        class TestService {
          constructor(private readonly logger: Logger) {}
          someMethod() {
            this.logger.log(random);
          }
        }

        @Controller("/")
github iamolegga / nestjs-pino / src / index.spec.ts View on Github external
beforeAll(async () => {
        stream = new MemoryStream();
        random = Math.random().toString();
        let logs = "";

        stream.on("data", (chunk: string) => {
          logs += chunk.toString();
        });

        @Injectable()
        class TestService {
          constructor(private readonly logger: Logger) {}
          someMethod() {
            this.logger.log(random);
          }
        }

        @Controller("/")
github mozilla / thimble.mozilla.org / default / index.js View on Github external
_defaultProjects[title].forEach(function(file) {
    switch(dataType) {
    case TAR_STREAM:
      result.entry({ name: file.path }, file.buffer);
      break;
    case FILE_STREAM:
      result.push({
        path: file.path,
        stream: MemoryStream.createReadStream(file.buffer),
        size: file.buffer.length
      });
      break;
    case BUFFER:
    default:
      result.push(file);
      break;
    }
  });

memorystream

This is lightweight memory stream module for node.js.

MIT
Latest version published 10 years ago

Package Health Score

67 / 100
Full package analysis