<commit_before>'use strict';

const lzo = require('bindings')('node_lzo');

// LZO error codes from lzoconf.h
const errCodes = { 
	'-1': 'LZO_E_ERROR',
	'-2': 'LZO_E_OUT_OF_MEMORY',
	'-3': 'LZO_E_NOT_COMPRESSIBLE',
	'-4': 'LZO_E_INPUT_OVERRUN',
	'-5': 'LZO_E_OUTPUT_OVERRUN',
	'-6': 'LZO_E_LOOKBEHIND_OVERRUN',
	'-7': 'LZO_E_EOF_NOT_FOUND',
	'-8': 'LZO_E_INPUT_NOT_CONSUMED',
	'-9': 'LZO_E_NOT_YET_IMPLEMENTED',
	'-10': 'LZO_E_INVALID_ARGUMENT',
	'-11': 'LZO_E_INVALID_ALIGNMENT',
	'-12': 'LZO_E_OUTPUT_NOT_CONSUMED',
	'-99': 'LZO_E_INTERNAL_ERROR',
	'-128': 'ERR_LZO_INIT_FAILED - lzo_init() failed' // Custom error, since LZO doesn't have a predefined one...
};

module.exports = {

	/**
	 * Compress data with the lzo compression algorithm
	 *
	 * @param {Buffer} input - If the parameter is not a buffer, the function will try to convert via `Buffer.from`
	 *
	 * @return {Buffer} The compressed data
	 */
	'compress': (input, length) => {
		if(!Buffer.isBuffer(input))
			input = Buffer.from(input);

		let output = Buffer.alloc(length || (input.length + (input.length / 16) + 64 + 3)),
			result = lzo.compress(input, output);

		if(result.err !== 0)
			throw new Error('Compression failed with code: ' + errCodes[result.err]);
		else
			return output.slice(0, result.len);
	},

	/**
	 * Decompress lzo-compressed data
	 *
	 * @param {Buffer} input - If the parameter is not a buffer, the function will try to convert via `Buffer.from`
	 *
	 * @return {Buffer} The decompressed data
	 */
	'decompress': (input, length) => {
		if(!Buffer.isBuffer(input))
			input = Buffer.from(input);

		let output = Buffer.alloc(length || (input.length * 3)),
			result = lzo.decompress(input, output);

		if(result.err !== 0)
			throw new Error('Decompression failed with code: ' + errCodes[result.err]);
		else
			return output.slice(0, result.len);
	},

	'version': lzo.version,
	'versionDate': lzo.versionDate,
	'errors': errCodes
};<commit_msg>Fix for #6: Removed the length argument to the compress function<commit_after>'use strict';

const lzo = require('bindings')('node_lzo');

// LZO error codes from lzoconf.h
const errCodes = { 
	'-1': 'LZO_E_ERROR',
	'-2': 'LZO_E_OUT_OF_MEMORY',
	'-3': 'LZO_E_NOT_COMPRESSIBLE',
	'-4': 'LZO_E_INPUT_OVERRUN',
	'-5': 'LZO_E_OUTPUT_OVERRUN',
	'-6': 'LZO_E_LOOKBEHIND_OVERRUN',
	'-7': 'LZO_E_EOF_NOT_FOUND',
	'-8': 'LZO_E_INPUT_NOT_CONSUMED',
	'-9': 'LZO_E_NOT_YET_IMPLEMENTED',
	'-10': 'LZO_E_INVALID_ARGUMENT',
	'-11': 'LZO_E_INVALID_ALIGNMENT',
	'-12': 'LZO_E_OUTPUT_NOT_CONSUMED',
	'-99': 'LZO_E_INTERNAL_ERROR',
	'-128': 'ERR_LZO_INIT_FAILED - lzo_init() failed' // Custom error, since LZO doesn't have a predefined one...
};

module.exports = {

	/**
	 * Compress data with the lzo compression algorithm
	 *
	 * @param {Buffer} input - If the parameter is not a buffer, the function will try to convert via `Buffer.from`
	 *
	 * @return {Buffer} The compressed data
	 */
	'compress': (input) => {
		if(!Buffer.isBuffer(input))
			input = Buffer.from(input);

		let output = Buffer.alloc(input.length + (input.length / 16) + 64 + 3),
				result = lzo.compress(input, output);

		if(result.err !== 0)
			throw new Error('Compression failed with code: ' + errCodes[result.err]);
		else
			return output.slice(0, result.len);
	},

	/**
	 * Decompress lzo-compressed data
	 *
	 * @param {Buffer} input - If the parameter is not a buffer, the function will try to convert via `Buffer.from`
	 *
	 * @return {Buffer} The decompressed data
	 */
	'decompress': (input, length) => {
		if(!Buffer.isBuffer(input))
			input = Buffer.from(input);

		let output = Buffer.alloc(length || (input.length * 3)),
			result = lzo.decompress(input, output);

		if(result.err !== 0)
			throw new Error('Decompression failed with code: ' + errCodes[result.err]);
		else
			return output.slice(0, result.len);
	},

	'version': lzo.version,
	'versionDate': lzo.versionDate,
	'errors': errCodes
};
{'fraction_non_alphanumeric': 0.16232106339468302, 'fraction_numerical': 0.015593047034764827, 'mean_word_length': 4.1690885072655215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1099097', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1446, 'n_words': 350}