NineSec Team Shell
Server IP : 92.205.26.207  /  Your IP : 216.73.216.16
Web Server : Apache
System : Linux 207.26.205.92.host.secureserver.net 4.18.0-553.60.1.el8_10.x86_64 #1 SMP Thu Jul 10 04:01:16 EDT 2025 x86_64
User : zikryat ( 1002)
PHP Version : 8.3.23
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/zikryat/public_html/node_modules/text-decoding/build/implementations/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/zikryat/public_html/node_modules/text-decoding/build/implementations/single-byte.js
const { end_of_stream, finished, isASCIIByte, decoderError, encoderError, isASCIICodePoint } = require('../utils');
const { indexPointerFor } = require('../indexes');

//
// 10. Legacy single-byte encodings
//

// 10.1 single-byte decoder
/**
 * @implements {Decoder}
 */
class SingleByteDecoder {
  /**
   * @param {!Array.<number>} index The encoding index.
   * @param {{fatal: boolean}} options
   */
  constructor(index, options) {
    const { fatal } = options
    this.fatal = fatal
    this.index = index
  }
  /**
   * @param {Stream} stream The stream of bytes being decoded.
   * @param {number} bite The next byte read from the stream.
   */
  handler(stream, bite) {
  // 1. If byte is end-of-stream, return finished.
    if (bite === end_of_stream)
      return finished

    // 2. If byte is an ASCII byte, return a code point whose value
    // is byte.
    if (isASCIIByte(bite))
      return bite

    // 3. Let code point be the index code point for byte − 0x80 in
    // index single-byte.
    var code_point = this.index[bite - 0x80]

    // 4. If code point is null, return error.
    if (code_point === null)
      return decoderError(this.fatal)

    // 5. Return a code point whose value is code point.
    return code_point
  }
}

// 10.2 single-byte encoder
/**
 * @implements {Encoder}
 */
class SingleByteEncoder {
  /**
   * @param {!Array.<?number>} index The encoding index.
   */
  constructor(index) {
    this.index = index
  }
  /**
   * @param {Stream} stream Input stream.
   * @param {number} code_point Next code point read from the stream.
   * @return {(number|!Array.<number>)} Byte(s) to emit.
   */
  handler(stream, code_point) {
    // 1. If code point is end-of-stream, return finished.
    if (code_point === end_of_stream)
      return finished

    // 2. If code point is an ASCII code point, return a byte whose
    // value is code point.
    if (isASCIICodePoint(code_point))
      return code_point

    // 3. Let pointer be the index pointer for code point in index
    // single-byte.
    const pointer = indexPointerFor(code_point, this.index)

    // 4. If pointer is null, return error with code point.
    if (pointer === null)
      encoderError(code_point)

    // 5. Return a byte whose value is pointer + 0x80.
    return pointer + 0x80
  }
}

module.exports.SingleByteDecoder = SingleByteDecoder
module.exports.SingleByteEncoder = SingleByteEncoder

NineSec Team - 2022