lib/converter.js
function getStringBuffer(s) {
  var buffer
    , n = typeof s === 'number' ? s : null
    // compressed header buffer
    , cheader
    , compressed;

  // Does it look like a number?
  if(n !== null
    || typeof s === 'string' && s.match(/^-?\d+$/)) {
    if(n === null) {
      n = parseInt(s);
    }
    if (n >= -128 && n <= 127) {
      buffer = new Buffer(1);
      buffer.writeInt8(n, 0);
      buffer = this.length(buffer, 0, true);
      return buffer;
    } else if (n >= -32768 && n <= 32767) {
      buffer = new Buffer(2);
      buffer.writeInt16LE(n, 0);
      buffer = this.length(buffer, 1, true);
      return buffer;
    } else if (n >= -2147483648 && n <= 2147483647) {
      buffer = new Buffer(4);
      buffer.writeInt32LE(n, 0);
      buffer = this.length(buffer, 2, true);
      return buffer;
    }
  }

  // It doesn't look like a number, or it's too big
  if(typeof s === 'string') {
    buffer = new Buffer(s, this.encoding);
  }else if(s instanceof Buffer){
    buffer = s;
  }

  if(buffer.length > this.compressionThreshold) {
    compressed = lzf.compress(buffer);
    if (compressed.length < buffer.length) {
      // It saved some space
      cheader = Buffer.concat(
        [
          this.getLengthEncoding(3, true),
          this.getLengthEncoding(compressed.length, false),
          this.getLengthEncoding(buffer.length, false)
        ]);
      return Buffer.concat(
        [cheader, compressed], cheader.length + compressed.length);
    }
  }

  buffer = this.length(buffer, buffer.length, false);
  return buffer;
}
function getStringBuffer(s) {
  var buffer
    , n = typeof s === 'number' ? s : null
    // compressed header buffer
    , cheader
    , compressed;

  // Does it look like a number?
  if(n !== null
    || typeof s === 'string' && s.match(/^-?\d+$/)) {
    if(n === null) {
      n = parseInt(s);
    }
    if (n >= -128 && n <= 127) {
      buffer = new Buffer(1);
      buffer.writeInt8(n, 0);
      buffer = this.length(buffer, 0, true);
      return buffer;
    } else if (n >= -32768 && n <= 32767) {
      buffer = new Buffer(2);
      buffer.writeInt16LE(n, 0);
      buffer = this.length(buffer, 1, true);
      return buffer;
    } else if (n >= -2147483648 && n <= 2147483647) {
      buffer = new Buffer(4);
      buffer.writeInt32LE(n, 0);
      buffer = this.length(buffer, 2, true);
      return buffer;
    }
  }

  // It doesn't look like a number, or it's too big
  if(typeof s === 'string') {
    buffer = new Buffer(s, this.encoding);
  }else if(s instanceof Buffer){
    buffer = s;
  }

  if(buffer.length > this.compressionThreshold) {
    compressed = lzf.compress(buffer);
    if (compressed.length < buffer.length) {
      // It saved some space
      cheader = Buffer.concat(
        [
          this.getLengthEncoding(3, true),
          this.getLengthEncoding(compressed.length, false),
          this.getLengthEncoding(buffer.length, false)
        ]);
      return Buffer.concat(
        [cheader, compressed], cheader.length + compressed.length);
    }
  }

  buffer = this.length(buffer, buffer.length, false);
  return buffer;
}
function getStringBuffer ( s ) { var buffer , n = typeof s === 'number' ? s : null // compressed header buffer , cheader , compressed ; // Does it look like a number? if ( n !== null || typeof s === 'string' && s . match ( / ^-?\d+$ / ) ) { if ( n === null ) { n = parseInt ( s ) ; } if ( n >= - 128 && n <= 127 ) { buffer = new Buffer ( 1 ) ; buffer . writeInt8 ( n , 0 ) ; buffer = this . length ( buffer , 0 , true ) ; return buffer ; } else if ( n >= - 32768 && n <= 32767 ) { buffer = new Buffer ( 2 ) ; buffer . writeInt16LE ( n , 0 ) ; buffer = this . length ( buffer , 1 , true ) ; return buffer ; } else if ( n >= - 2147483648 && n <= 2147483647 ) { buffer = new Buffer ( 4 ) ; buffer . writeInt32LE ( n , 0 ) ; buffer = this . length ( buffer , 2 , true ) ; return buffer ; } } // It doesn't look like a number, or it's too big if ( typeof s === 'string' ) { buffer = new Buffer ( s , this . encoding ) ; } else if ( s instanceof Buffer ) { buffer = s ; } if ( buffer . length > this . compressionThreshold ) { compressed = lzf . compress ( buffer ) ; if ( compressed . length < buffer . length ) { // It saved some space cheader = Buffer . concat ( [ this . getLengthEncoding ( 3 , true ) , this . getLengthEncoding ( compressed . length , false ) , this . getLengthEncoding ( buffer . length , false ) ] ) ; return Buffer . concat ( [ cheader , compressed ] , cheader . length + compressed . length ) ; } } buffer = this . length ( buffer , buffer . length , false ) ; return buffer ; }
Get a string buffer.
Get a string buffer .