How to use bl - 10 common examples

To help you get started, we’ve selected a few bl 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 remotelib / remote-lib / packages / remote-instance / src / parser.js View on Github external
encodeArgumentsList(argumentsList = []) {
    const bufferList = bl();

    // Trim undefined arguments
    let maxIndex = argumentsList.length - 1;
    while (maxIndex >= 0 && argumentsList[maxIndex] === undefined) {
      maxIndex -= 1;
    }

    // Encode only the necessary values
    for (let i = 0; i <= maxIndex; i += 1) {
      const buffer = this.encode(argumentsList[i]);
      bufferList.append(buffer);
    }

    return bufferList;
  }
github mcollina / node-coap / lib / outgoing_message.js View on Github external
function OutgoingMessage(request, send) {
  BufferList.call(this)

  this._packet = {
      messageId: request.messageId
    , token: request.token
    , options: []
    , confirmable: false
    , ack: false
    , reset: false
  }

  var that = this

  if (request.confirmable) {
    // replying in piggyback
    this._packet.ack = true
github mcollina / node-coap / lib / outgoing_message.js View on Github external
OutgoingMessage.prototype.end = function(a, b) {
  BufferList.prototype.end.call(this, a, b)

  var packet = this._packet
    , that = this

  packet.code = toCode(this.code || this.statusCode)
  packet.payload = this

  if (this._ackTimer)
    clearTimeout(this._ackTimer)

  this._send(this, packet)

  // easy clean up after generating the packet
  delete this._packet.payload

  return this
github tommy351 / kosko / packages / cli / src / commands / __tests__ / new.ts View on Github external
import BufferList from "bl";
import { baseOptions } from "../../base";
import { help } from "../../cli/help";
import { Logger } from "../../cli/logger";
import { ParseError } from "../../cli/parse";
import { Context } from "../../cli/types";
import { newCmd } from "../new";

const resolveMock = resolve as jest.Mock;
const requireMock = requireDefault as jest.Mock;

jest.mock("../../cli/help");
jest.mock("@kosko/require");
jest.mock("@kosko/template");

const bl = new BufferList();
const ctx: Context = { logger: new Logger(bl) };

beforeEach(() => jest.resetAllMocks());

describe("when template is not set", () => {
  test("should print help", async () => {
    await newCmd.exec(ctx, []);
    expect(help).toHaveBeenCalledTimes(1);
    expect(help).toHaveBeenCalledWith(newCmd);
  });
});

describe("when template is set", () => {
  describe("and module does not exist", () => {
    const resolveErr = new Error("resolve error");
github tommy351 / kosko / packages / cli / src / cli / __tests__ / help.ts View on Github external
beforeEach(async () => {
  bl = new BufferList();
  await help(cmd, bl);
});
github tommy351 / kosko / packages / generate / src / __tests__ / print.ts View on Github external
beforeEach(() => {
  bl = new BufferList();
  print(result, {
    ...options,
    writer: bl
  });
});
github ipfs-shipyard / paperhub / app / scripts / services / api.js View on Github external
return new Promise((resolve, reject) => {
    stream.pipe(bl((err, buf) => {
      if (err) return reject(err)
      resolve(buf)
    }))
  })
}
github remotelib / remote-lib / packages / remote-instance / src / parser.js View on Github external
  decodeArgumentsList(buffer = bl()) {
    const bufferList = buffer instanceof bl ? buffer : bl().append(buffer);
    const argumentsList = [];

    while (bufferList.length) {
      argumentsList.push(this.decode(bufferList));
    }

    return argumentsList;
  }
github remotelib / remote-lib / packages / remote-instance / src / parser.js View on Github external
decodeArgumentsList(buffer = bl()) {
    const bufferList = buffer instanceof bl ? buffer : bl().append(buffer);
    const argumentsList = [];

    while (bufferList.length) {
      argumentsList.push(this.decode(bufferList));
    }

    return argumentsList;
  }
github nodeWechat / wechat4u / src / core.js View on Github external
} else if (Buffer.isBuffer(file)) {
          if (!filename) {
            return reject(new Error('文件名未知'))
          }
          name = filename
          type = mime.lookup(name)
          size = file.length
          data = file
          return resolve()
        } else if (file.readable) {
          if (!file.path && !filename) {
            return reject(new Error('文件名未知'))
          }
          name = path.basename(file.path || filename)
          type = mime.lookup(name)
          file.pipe(bl((err, buffer) => {
            if (err) {
              return reject(err)
            }
            size = buffer.length
            data = buffer
            return resolve()
          }))
        }
      }).then(() => {
        ext = name.match(/.*\.(.*)/)

bl

Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!

MIT
Latest version published 1 month ago

Package Health Score

89 / 100
Full package analysis

Popular bl functions