<commit_before>﻿import enums = require("./sftp-enums");
import charsets = require("./charsets");

import SftpPacketType = enums.SftpPacketType;
import encodeUTF8 = charsets.encodeUTF8;

export class SftpPacket {
    type: SftpPacketType|string;
    id: number;

    buffer: Buffer;
    position: number;
    length: number;

    constructor() {
    }

    check(count: number): void {
        var remaining = this.length - this.position;
        if (count > remaining)
            throw new Error("Unexpected end of packet");
    }

    skip(count: number): void {
        this.check(count);
        this.position += count;
    }

    static isBuffer(obj: any): boolean {
        return Buffer.isBuffer(obj); //WEB: return obj && obj.buffer instanceof ArrayBuffer && typeof obj.byteLength !== "undefined";
    }

    static toString(packetType: SftpPacketType|string): string {<commit_msg>Minor optimization in SftpPacket.toString<commit_after>﻿import enums = require("./sftp-enums");
import charsets = require("./charsets");

import SftpPacketType = enums.SftpPacketType;
import encodeUTF8 = charsets.encodeUTF8;

export class SftpPacket {
    type: SftpPacketType|string;
    id: number;

    buffer: Buffer;
    position: number;
    length: number;

    constructor() {
    }

    check(count: number): void {
        var remaining = this.length - this.position;
        if (count > remaining)
            throw new Error("Unexpected end of packet");
    }

    skip(count: number): void {
        this.check(count);
        this.position += count;
    }

    static isBuffer(obj: any): boolean {
        return Buffer.isBuffer(obj); //WEB: return obj && obj.buffer instanceof ArrayBuffer && typeof obj.byteLength !== "undefined";
    }

    static toString(packetType: SftpPacketType|string): string {
        if (typeof packetType === "string") return packetType;
{'fraction_non_alphanumeric': 0.1193151417870519, 'fraction_numerical': 0.002140181915462814, 'mean_word_length': 3.0652173913043477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1643785', 'n_tokens_mistral': 553, 'n_tokens_neox': 529, 'n_words': 143}