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