Path: blob/main/extensions/media-preview/src/binarySizeStatusBarEntry.ts
4772 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as vscode from 'vscode';6import { PreviewStatusBarEntry } from './ownedStatusBarEntry';789class BinarySize {10static readonly KB = 1024;11static readonly MB = BinarySize.KB * BinarySize.KB;12static readonly GB = BinarySize.MB * BinarySize.KB;13static readonly TB = BinarySize.GB * BinarySize.KB;1415static formatSize(size: number): string {16if (size < BinarySize.KB) {17return vscode.l10n.t("{0}B", size);18}1920if (size < BinarySize.MB) {21return vscode.l10n.t("{0}KB", (size / BinarySize.KB).toFixed(2));22}2324if (size < BinarySize.GB) {25return vscode.l10n.t("{0}MB", (size / BinarySize.MB).toFixed(2));26}2728if (size < BinarySize.TB) {29return vscode.l10n.t("{0}GB", (size / BinarySize.GB).toFixed(2));30}3132return vscode.l10n.t("{0}TB", (size / BinarySize.TB).toFixed(2));33}34}3536export class BinarySizeStatusBarEntry extends PreviewStatusBarEntry {3738constructor() {39super('status.imagePreview.binarySize', vscode.l10n.t("Image Binary Size"), vscode.StatusBarAlignment.Right, 100);40}4142public show(owner: unknown, size: number | undefined) {43if (typeof size === 'number') {44super.showItem(owner, BinarySize.formatSize(size));45} else {46this.hide(owner);47}48}49}505152