How to use the string_decoder.StringDecoder function in string_decoder

To help you get started, we’ve selected a few string_decoder 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 ibm-messaging / mq-mqi-nodejs / samples / amqssub.js View on Github external
/*
 * This is an example of a Node.js program to subscribe to publications
 * made through IBM MQ.
 *
 * The topic and queue manager name can be given as parameters on the
 * command line. Defaults are coded in the program.
 *
 */

// Import the MQ package
var mq = require('ibmmq');
var MQC = mq.MQC; // Want to refer to this export directly for simplicity

// Import any other packages needed
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');

// The queue manager and queue to be used
var qMgr = "QM1";
var topicString = "dev/JSTopic";

// Global variables
var ok = true;


// Define some functions that will be used from the main flow
function getMessages(hObj) {
  while (ok) {
    getMessage(hObj);
  }
}
github apigee / trireme / node10 / node10src / src / main / javascript / io / apigee / trireme / node10 / node / readline.js View on Github external
self._ttyWrite(s, key);
  }

  function onresize() {
    self._refreshLine();
  }

  if (!this.terminal) {
    input.on('data', ondata);
    input.on('end', onend);
    self.once('close', function() {
      input.removeListener('data', ondata);
      input.removeListener('end', onend);
    });
    var StringDecoder = require('string_decoder').StringDecoder; // lazy load
    this._decoder = new StringDecoder('utf8');

  } else {

    exports.emitKeypressEvents(input);

    // input usually refers to stdin
    input.on('keypress', onkeypress);

    // Current line
    this.line = '';

    this._setRawMode(true);
    this.terminal = true;

    // Cursor position on the line.
    this.cursor = 0;
github jonsherrard / beacon-lock / app.js View on Github external
var powerThreshold = -90;

try {
  var config = require('./config.json');
  deviceId = config.deviceId;
  console.log('Searching for device with id: ', deviceId);
} catch (e) {
  console.warn("Couldn't find a config file - Searching for nearby devices");
}


var exec = require('child_process').exec,
    child;

var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');

var scanStart = function(data) {
  console.log('scan start data: ', data);
};

var discoverCallback = function(data) {
  if (data.advertisement.serviceData.length) {
    var buff = data.advertisement.serviceData[0].data;
    buff = decoder.write(buff);
    buff = buff.substring(2);
    if (!deviceId) {
      console.log('\nAdvertised name: ', buff +'\n', 'Distance: ', parseInt(data.rssi) + '\n', 'Device identifier: ', data.uuid);
    } else if (data.uuid == deviceId) {
      console.log('Device: ', buff, '\n', 'Distance: ', data.rssi, '\n');
    }
    if ((data.rssi < powerThreshold) && (data.uuid == deviceId)) {
github rjanicek / connectwise-action-api / sax-1.1.1.patched.js View on Github external
SAXStream.prototype.write = function (data) {
  if (typeof Buffer === 'function' &&
      typeof Buffer.isBuffer === 'function' &&
      Buffer.isBuffer(data)) {
    if (!this._decoder) {
      var SD = require('string_decoder').StringDecoder
      this._decoder = new SD('utf8')
    }
    data = this._decoder.write(data);
  }

  this._parser.write(data.toString())
  this.emit("data", data)
  return true
}
github postaljs / postal.js / example / node / node_modules / express / node_modules / connect / node_modules / formidable / lib / incoming_form.js View on Github external
IncomingForm.prototype.handlePart = function ( part ) {
	var self = this;

	if ( part.filename === undefined ) {
		var value = ''
			, decoder = new StringDecoder( this.encoding );

		part.on( 'data', function ( buffer ) {
			self._fieldsSize += buffer.length;
			if ( self._fieldsSize > self.maxFieldsSize ) {
				self._error( new Error( 'maxFieldsSize exceeded, received ' + self._fieldsSize + ' bytes of field data' ) );
				return;
			}
			value += decoder.write( buffer );
		} );

		part.on( 'end', function () {
			self.emit( 'field', part.name, value );
		} );
		return;
	}
github yoshuawuyts / bindingify / index.js View on Github external
function bindingify (file) {
  if (!/\.js$/.test(file)) return through()

  var decoder = new StringDecoder('utf8')
  var src = ''

  return through(write, flush)

  function write (chunk, _, cb) {
    src += decoder.write(chunk)
    cb()
  }

  function flush (cb) {
    src += decoder.end()

    var output = falafel(src, function (node) {
      if (node.type !== 'CallExpression') return
      if (!node.arguments.length) return
      if (!node.callee || !node.callee.arguments) return
github north / generator-style-prototype / section / index.js View on Github external
'use strict';

var yeoman = require('yeoman-generator');
var _s = require('underscore.string');
var yaml = require('js-yaml');
var fs = require('fs-extra');
var chalk = require('chalk');
var inquirer = require("inquirer");
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');

var SPSectionGenerator = yeoman.generators.Base.extend({
  init: function () {
    try {
      this.sections = yaml.safeLoad(fs.readFileSync('config/sections.yml', 'utf8'));
    }
    catch (e) {
      if (e.errno && e.errno === 34) {
        console.log(chalk.red('Please run this generator from the root of your Style Prototype'));
      }
      else if (e.name && e.name === 'YAMLException') {
        if (e.message) {
          console.log(chalk.red(e.message));
        }
      }
    }
github handshake-org / hs-airdrop / lib / readline.js View on Github external
async function readLine(prefix = '', secret = false) {
  assert(typeof prefix === 'string');
  assert(typeof secret === 'boolean');

  const {stdin, stdout} = process;
  const decoder = new StringDecoder('utf8');

  let out = '';

  stdin.setRawMode(true);
  stdin.resume();

  if (prefix)
    stdout.write(`${prefix} `);

  return new Promise((resolve, reject) => {
    const cleanup = () => {
      stdin.removeListener('error', onError);
      stdin.removeListener('data', onData);
      stdin.pause();
      stdin.setRawMode(false);
    };
github esrlabs / chipmunk / app / server / libs / service.adb.js View on Github external
constructor(settings) {
        super();
        this._settings          = this._validateSettings(settings);
        this._process           = new SpawnProcess();
        this._buffer            = new StringTimerBuffer(STREAM_BUFFER_OPTIONS.LENGTH, STREAM_BUFFER_OPTIONS.DURATION);
        this._GUID              = (require('uuid/v1'))();
        this._decoder           = new StringDecoder('utf8');
        this._rest              = '';
        this._onProcessData     = this._onProcessData.bind(this);
        this._onProcessClose    = this._onProcessClose.bind(this);
        this._onBuffer          = this._onBuffer.bind(this);
        this._bindBuffer();
        this.EVENTS         = {
            ON_DATA : Symbol(),
            ON_CLOSE: Symbol()
        };
    }
github ideino / ideino-linino-lib / lib / servo.js View on Github external
/***
 * file: servo.js
 * author: https://github.com/quasto, https://github.com/andrea-83
 * based on: https://github.com/fivdi/onoff/blob/master/onoff.js 
 ***/

var fs = require('fs'),
    pwmRootPath = '/sys/class/pwm/pwmchip0/';
	
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');

var conf = {
	'16' : {
				'inf' 	:	560000,
				'sup'	:	2400000,
				'period':	20000000,
				'rap' 	:	((2400000-560000)/180),		//tempi in ns 
				'byte'	:	9
			}
}


function Servo(pin_register, timer) {

	this.gpio = pin_register.NUM;
	this.map = pin_register.MAP;

string_decoder

The string_decoder module from Node core

MIT
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis