<commit_before># Copyright (c) 2014 <NAME>, MIT License
util                  = require("abstract-object/lib/util")
inherits              = util.inherits
isInheritedFrom       = util.isInheritedFrom
isNumber              = util.isNumber
createObject          = util.createObject
Errors                = require('abstract-object/Error')
createError           = Errors.createError
AbstractError         = Errors.AbstractError
NotImplementedError   = Errors.NotImplementedError
InvalidArgumentError  = Errors.InvalidArgumentError
InvalidFormatError    = Errors.InvalidFormatError
InvalidUtf8Error      = createError("InvalidUtf8", 0x81, InvalidFormatError)
isBuffer              = Buffer.isBuffer

Errors.InvalidUtf8Error = InvalidUtf8Error

module.exports = class Codec
  @bufferSize: 1024
  @getBuffer: (aBufferSize) ->
    if not Codec.buffer or Codec.buffer.length < aBufferSize
      aBufferSize ||= Codec.bufferSize
      Codec.buffer = new Buffer(aBufferSize)
      Codec.bufferSize = aBufferSize
      
    Codec.buffer
  @_codecs: {}
  @_aliases: {}
  codecs = Codec._codecs
  aliases = Codec._aliases
  constructor: (aCodecName, aBufferSize)->
    if isNumber aCodecName
      aBufferSize = aCodecName
      aCodecName = null
    if not (this instanceof Codec)
      # arguments.callee is forbidden if strict mode enabled.
      if not aCodecName
        try aCodecName = Codec.getNameFromClass(arguments.callee.caller)
      aCodecName = aCodecName.toLowerCase()
      result = codecs[aCodecName]
      if not result?
        alias = aCodecName
        aCodecName = Codec.getRealNameFromAlias alias
        if aCodecName
          result = codecs[aCodecName]
      if result instanceof Codec
        result.init(aBufferSize) if aBufferSize > 0
      else if result
        result = Math.max result, aBufferSize if aBufferSize > 0
        result = undefined if result < 0 or result is NaN<commit_msg>* Codec constructor can pass a codec instance and return it directly.<commit_after># Copyright (c) 2014 <NAME>, MIT License
util                  = require("abstract-object/lib/util")
inherits              = util.inherits
isInheritedFrom       = util.isInheritedFrom
isNumber              = util.isNumber
createObject          = util.createObject
Errors                = require('abstract-object/Error')
createError           = Errors.createError
AbstractError         = Errors.AbstractError
NotImplementedError   = Errors.NotImplementedError
InvalidArgumentError  = Errors.InvalidArgumentError
InvalidFormatError    = Errors.InvalidFormatError
InvalidUtf8Error      = createError("InvalidUtf8", 0x81, InvalidFormatError)
isBuffer              = Buffer.isBuffer

Errors.InvalidUtf8Error = InvalidUtf8Error

module.exports = class Codec
  @bufferSize: 1024
  @getBuffer: (aBufferSize) ->
    if not Codec.buffer or Codec.buffer.length < aBufferSize
      aBufferSize ||= Codec.bufferSize
      Codec.buffer = new Buffer(aBufferSize)
      Codec.bufferSize = aBufferSize
      
    Codec.buffer
  @_codecs: {}
  @_aliases: {}
  codecs = Codec._codecs
  aliases = Codec._aliases
  constructor: (aCodecName, aBufferSize)->
    if isNumber aCodecName
      aBufferSize = aCodecName
      aCodecName = null
    else if aCodecName instanceof Codec
      aCodecName.init(aBufferSize) if aBufferSize > 0
      return aCodecName
    if not (this instanceof Codec)
      # arguments.callee is forbidden if strict mode enabled.
      if not aCodecName
        try aCodecName = Codec.getNameFromClass(arguments.callee.caller)
      aCodecName = aCodecName.toLowerCase()
      result = codecs[aCodecName]
      if not result?
        alias = aCodecName
        aCodecName = Codec.getRealNameFromAlias alias
        if aCodecName
          result = codecs[aCodecName]
      if result instanceof Codec
        result.init(aBufferSize) if aBufferSize > 0
      else if result
        result = Math.max result, aBufferSize if aBufferSize > 0
        result = undefined if result < 0 or result is NaN
{'fraction_non_alphanumeric': 0.06820461384152457, 'fraction_numerical': 0.009277833500501504, 'mean_word_length': 2.82088122605364, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '3918270', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1155, 'n_words': 291}