<commit_before>'use strict';

const StorageItem = require('./StorageItem'),
    BlobTypes = require('./../Constants').BlobTypes;

class Blob extends StorageItem {
    constructor(name, httpHeader, blobType) {
        super(name, httpHeader);
        if (blobType) {
            this.blobType = blobType;
            this.httpProps['x-ms-blob-type'] = blobType;
        }
        this.snapshot = false;
        this._addProps(httpHeader);
    }

    _addProps(httpHeader) {
        if (this.blobType === BlobTypes.AppendBlob) {
            this.httpProps['x-ms-blob-committed-block-count'] = 0;
        }
        if (this.blobType === BlobTypes.PageBlob) {
            this.httpProps['x-ms-blob-content-length'] = httpHeader['x-ms-blob-content-length'];
            this.httpProps['x-ms-page-write'] = httpHeader['x-ms-page-write'] ? httpHeader['x-ms-page-write'].toUpperCase() : undefined;
            this.httpProps['x-ms-if-sequence-number-le'] = httpHeader['x-ms-if-sequence-number-le'];
            this.httpProps['x-ms-if-sequence-number-lt'] = httpHeader['x-ms-if-sequence-number-lt'];
            this.httpProps['x-ms-if-sequence-number-eq'] = httpHeader['x-ms-if-sequence-number-eq'];
            this.httpProps['If-Modified-Since'] = httpHeader['If-Modified-Since'] || httpHeader['if-modified-since'];
            this.httpProps['If-Unmodified-Since'] = httpHeader['If-Unmodified-Since'] || httpHeader['if-unmodified-since'];
            this.httpProps['If-Match'] = httpHeader['If-Match'] || httpHeader['if-match'];
            this.httpProps['If-None-Match'] = httpHeader['If-None-Match'] || httpHeader['if-none-match'];
            Object.keys(this.httpProps).forEach((key) => {
                if (this.httpProps[key] === undefined) {
                    delete this.httpProps[key];
                }
            });
        }
    }

    markAsSnapshot(dateTime) {
        this.snapshot = true;
    }

    /**
     * Checks whether blob name corresponds to a virtual directory. This is true if the name ends with at least trailing slash.
     * 
     * @returns true if name is followed by at least one '/' character, false otherwise.  
     * 
     * @memberof Blob
     */
    isVirtualDirectory() {
        return this.name.match('.*\/+$') !== null;
    }

    isSnapshot() {
        return this.snapshot;
    }

    /**
     * The name of the blob that is used in the web and disk interface. 
     * 
     * @memberof Blob
     */
    publicName() {
        if (this.isSnapshot()) {
            return `${this.name}-${Date.parse(this.httpProps['Last-Modified'])}`;
        }
        if (this.isVirtualDirectory()) {
            return Buffer.from(this.name, 'utf8').toString('base64');
        }
        return this.name;
    }
}

module.exports = Blob;<commit_msg>refactoring<commit_after>'use strict';

const StorageItem = require('./StorageItem'),
    BlobTypes = require('./../Constants').BlobTypes;

class Blob extends StorageItem {
    constructor(name, httpHeader, blobType) {
        super(name, httpHeader);
        if (blobType) {
            this.blobType = blobType;
            this.httpProps['x-ms-blob-type'] = blobType;
        }
        this._addProps(httpHeader);
    }

    _addProps(httpHeader) {
        if (this.blobType === BlobTypes.AppendBlob) {
            this.httpProps['x-ms-blob-committed-block-count'] = 0;
        }
        if (this.blobType === BlobTypes.PageBlob) {
            this.httpProps['x-ms-blob-content-length'] = httpHeader['x-ms-blob-content-length'];
            this.httpProps['x-ms-page-write'] = httpHeader['x-ms-page-write'] ? httpHeader['x-ms-page-write'].toUpperCase() : undefined;
            this.httpProps['x-ms-if-sequence-number-le'] = httpHeader['x-ms-if-sequence-number-le'];
            this.httpProps['x-ms-if-sequence-number-lt'] = httpHeader['x-ms-if-sequence-number-lt'];
            this.httpProps['x-ms-if-sequence-number-eq'] = httpHeader['x-ms-if-sequence-number-eq'];
            this.httpProps['If-Modified-Since'] = httpHeader['If-Modified-Since'] || httpHeader['if-modified-since'];
            this.httpProps['If-Unmodified-Since'] = httpHeader['If-Unmodified-Since'] || httpHeader['if-unmodified-since'];
            this.httpProps['If-Match'] = httpHeader['If-Match'] || httpHeader['if-match'];
            this.httpProps['If-None-Match'] = httpHeader['If-None-Match'] || httpHeader['if-none-match'];
            Object.keys(this.httpProps).forEach((key) => {
                if (this.httpProps[key] === undefined) {
                    delete this.httpProps[key];
                }
            });
        }
    }

    setSnapshotDate(date) {
        this.snapshotDate = date || this.httpProps['Last-Modified'];
    }

    /**
     * Checks whether blob name corresponds to a virtual directory. This is true if the name ends with at least trailing slash.
     * 
     * @returns true if name is followed by at least one '/' character, false otherwise.  
     * 
     * @memberof Blob
     */
    isVirtualDirectory() {
        return this.name.match('.*\/+$') !== null;
    }

    isSnapshot() {
        return this.snapshotDate !== undefined;
    }

    /**
     * The name of the blob that is used in the web and disk interface. 
     * 
     * @memberof Blob
     */
    publicName() {
        if (this.isSnapshot()) {
            return `${this.name}-${Date.parse(this.snapshotDate)}`;
        }
        if (this.isVirtualDirectory()) {
            return Buffer.from(this.name, 'utf8').toString('base64');
        }
        return this.name;
    }
}

module.exports = Blob;
{'fraction_non_alphanumeric': 0.15921737569556632, 'fraction_numerical': 0.0014360078980434393, 'mean_word_length': 2.2970414201183433, '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': '3577261', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1664, 'n_words': 279}