Path: blob/main/src/vs/workbench/common/editor/binaryEditorModel.ts
3296 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 { EditorModel } from './editorModel.js';6import { URI } from '../../../base/common/uri.js';7import { IFileService } from '../../../platform/files/common/files.js';8import { Mimes } from '../../../base/common/mime.js';910/**11* An editor model that just represents a resource that can be loaded.12*/13export class BinaryEditorModel extends EditorModel {1415private readonly mime = Mimes.binary;1617private size: number | undefined;18private etag: string | undefined;1920constructor(21readonly resource: URI,22private readonly name: string,23@IFileService private readonly fileService: IFileService24) {25super();26}2728/**29* The name of the binary resource.30*/31getName(): string {32return this.name;33}3435/**36* The size of the binary resource if known.37*/38getSize(): number | undefined {39return this.size;40}4142/**43* The mime of the binary resource if known.44*/45getMime(): string {46return this.mime;47}4849/**50* The etag of the binary resource if known.51*/52getETag(): string | undefined {53return this.etag;54}5556override async resolve(): Promise<void> {5758// Make sure to resolve up to date stat for file resources59if (this.fileService.hasProvider(this.resource)) {60const stat = await this.fileService.stat(this.resource);61this.etag = stat.etag;62if (typeof stat.size === 'number') {63this.size = stat.size;64}65}6667return super.resolve();68}69}707172