Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/common/editor/binaryEditorModel.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { EditorModel } from './editorModel.js';
7
import { URI } from '../../../base/common/uri.js';
8
import { IFileService } from '../../../platform/files/common/files.js';
9
import { Mimes } from '../../../base/common/mime.js';
10
11
/**
12
* An editor model that just represents a resource that can be loaded.
13
*/
14
export class BinaryEditorModel extends EditorModel {
15
16
private readonly mime = Mimes.binary;
17
18
private size: number | undefined;
19
private etag: string | undefined;
20
21
constructor(
22
readonly resource: URI,
23
private readonly name: string,
24
@IFileService private readonly fileService: IFileService
25
) {
26
super();
27
}
28
29
/**
30
* The name of the binary resource.
31
*/
32
getName(): string {
33
return this.name;
34
}
35
36
/**
37
* The size of the binary resource if known.
38
*/
39
getSize(): number | undefined {
40
return this.size;
41
}
42
43
/**
44
* The mime of the binary resource if known.
45
*/
46
getMime(): string {
47
return this.mime;
48
}
49
50
/**
51
* The etag of the binary resource if known.
52
*/
53
getETag(): string | undefined {
54
return this.etag;
55
}
56
57
override async resolve(): Promise<void> {
58
59
// Make sure to resolve up to date stat for file resources
60
if (this.fileService.hasProvider(this.resource)) {
61
const stat = await this.fileService.stat(this.resource);
62
this.etag = stat.etag;
63
if (typeof stat.size === 'number') {
64
this.size = stat.size;
65
}
66
}
67
68
return super.resolve();
69
}
70
}
71
72