Encode buffer in the array
492911
function encodeBuffer( encoder, buffer_type, mime_type, buffer ) {

	// Write buffer header according to buffer length
	if (buffer.length < UINT8_MAX) {
		encoder.stream8.write( pack1b( PRIM_OP.BUFFER | buffer_type | 0x00 ) );
		encoder.stream8.write( pack1b( buffer.length ) );
		encoder.counters.dat_hdr+=2;
	} else if (buffer.length < UINT16_MAX) {
		encoder.stream8.write( pack1b( PRIM_OP.BUFFER | buffer_type | 0x08 ) );
		encoder.stream16.write( pack2b( buffer.length ) );
		encoder.counters.dat_hdr+=3;
	} else if (buffer.length < UINT32_MAX) {
		encoder.stream8.write( pack1b( PRIM_OP.BUFFER | buffer_type | 0x10 ) );
		encoder.stream32.write( pack4b( buffer.length ) );
		encoder.counters.dat_hdr+=5;
	} else {
		// 4 Gigs? Are you serious? Of course we can fit it in a Float64, but WHY?
		throw new Errors.RangeError('The buffer you are trying to encode is bigger than the supported size!');
	}

	// Write MIME Type (from string lookup table)
	if (mime_type != null) {
		encoder.stream16.write( pack2b( mime_type ) );
		encoder.counters.dat_hdr+=2;
	}

	// Write buffer
	if (buffer_type === PRIM_BUFFER_TYPE.STRING_UTF8) {

		// NOTE: UTF-8 is a special case. For optimisation
		// purposes it's better to use the 16-bit stream
		// rather than downcasting to 8-bit and then 
		// re-constructing the 16-bit stream at decoding time.
		encoder.stream16.write( packTypedArray(buffer) );

	} else {
		encoder.stream8.write( packTypedArray(buffer) );
	}

}
453647
function __arrayBufferConcat(buffers) {
	let totalLength = 0;
	for (const buffer of buffers) {
		totalLength += buffer.byteLength;
	}
	const result = new Uint8Array(totalLength);
	let offset = 0;
	for (const buffer of buffers) {
		result.set(new Uint8Array(buffer), offset);
		offset += buffer.byteLength;
	}
	return result.buffer;
}
500699
public void encodeBuffer(ByteBuffer aBuffer, OutputStream aStream)
        throws IOException {
        byte [] buf = getBytes(aBuffer);
        encodeBuffer(buf, aStream);
    }
909157
function encode(buf) {
	if (buf.length != 8) {
		throw new TypeError("Buffer must be length 8");
	}

	var num = new UInt64(buf.readUInt32BE(4), buf.readUInt32BE(0));
	var str = "";
	do {
		num.div(SIXTY_TWO);
		str = CHARS[num.remainder] + str;
	} while (num.greaterThan(ZERO));

	return str;
}
1024098
int encodevs(float[] a, Buffer b, int step, int addmul) {
        int best = besterror(a, step, addmul);
        return (encode(best, b));
    }
39143
function encodeBuffer(packet, supportsBinary, callback) {
  if (!supportsBinary) {
    return exports.encodeBase64Packet(packet, callback);
  }

  var data = packet.data;
  var typeBuffer = new Buffer(1);
  typeBuffer[0] = packets[packet.type];
  return callback(Buffer.concat([typeBuffer, data]));
}
284761
function() {
    var b = this.buffer, o = this.offset, carry = 1;
    for (var i = o + 7; i >= o; i--) {
      var v = (b[i] ^ 0xff) + carry;
      b[i] = v & 0xff;
      carry = v >> 8;
    }
  }
1206460
function insertHexadecimalToByteArray (str, buffer, from) {
  for (let i = 0; i < str.length; i += 2) {
    buffer[from] = parseInt(str.substr(i, 2), 16)
    from++
  }
  return buffer
}
713067
function arrayBufferToDataURL(arrayBuffer, mimeType) {
  var uint8 = new Uint8Array(arrayBuffer);
  var data = '';

  // TypedArray.prototype.forEach is not supported in some browsers.
  forEach(uint8, function (value) {
    data += fromCharCode(value);
  });

  return 'data:' + mimeType + ';base64,' + btoa(data);
}
1145143
protected void encode(ByteBuffer txBuffer) {

        txBuffer.position(4); // Length int
        txBuffer.put(data);

        int length = txBuffer.position();

        txBuffer.rewind();

        txBuffer.putInt(length);

        txBuffer.position(length);
    }
760237
function encodeVarInt(value) {
    var bytes = [], cursor, length, i;

    do {
        bytes.push(value & 0x7F);
        value >>= 7;
    } while (value > 0);

    length = bytes.length;
    cursor = new BufferCursor(new buffer.Buffer(length));

    for (i = length - 1; i >= 0; i -= 1) {
        if (i > 0) {
            bytes[i] |= 0x80;
        }

        cursor.writeUInt8(bytes[i]);
    }

    return cursor.buffer;
}
1245800
function ucs2encode(array) {
		return map(array, function(value) {
			var output = '';
			if (value > 0xFFFF) {
				value -= 0x10000;
				output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
				value = 0xDC00 | value & 0x3FF;
			}
			output += stringFromCharCode(value);
			return output;
		}).join('');
	}
1000619
function toBuffer(arrayBuffer) {
    if (Array.isArray(arrayBuffer)) {
        return new Buffer(arrayBuffer);
    }
    else {
        var length = arrayBuffer.byteLength;
        var view = new DataView(arrayBuffer, 0, length);
        var buffer = new Buffer(length);
        for (var i = 0, l = length; i < l; i++) {
            buffer[i] = view.getUint8(i, false);
        }
    }

    return buffer;
}
530117
function encode (data, buffer, offset) {
  var buffers = []
  var result = null

  encode._encode(buffers, data)
  result = Buffer.concat(buffers)
  encode.bytes = result.length

  if (Buffer.isBuffer(buffer)) {
    result.copy(buffer, offset)
    return buffer
  }

  return result
}
286620
function encode(args) {
  const argc = args.length;
  let len = 1;
  let off = 0;
  var i;

  // data length
  for (i = 0; i < argc; i += 1) {
    len += 4 + args[i].length;
  }

  // buffer
  const buf = Buffer.alloc(len);

  // pack meta
  buf[off += 1] = (VERSION << 4) | argc;

  // pack args
  for (i = 0; i < argc; i += 1) {
    const arg = args[i];

    buf.writeUInt32BE(arg.length, off);
    off += 4;

    arg.copy(buf, off);
    off += arg.length;
  }

  return buf;
}
383508
function encodeFloat(value) {
    let buffer = new ByteBuffer();
    buffer.littleEndian = true;
    buffer.limit = 8;
    if (value === null) {
        return buffer;
    }
    return buffer.writeFloat(value);
}
652565
function amf0encSArray(a) {
    console.log('Do strict array!');
    var buf = new Buffer(5);
    buf.writeUInt8(0x0A,0);
    buf.writeUInt32BE(a.length,1);
    var i;
    for (i=0;i< a.length;i++) {
        buf = Buffer.concat([buf,amf0EncodeOne(a[i])]);
    }
    return buf;
}