mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
[html] clean up request service: add CustomDataRequestService #135459
This commit is contained in:
@@ -5,28 +5,15 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { Uri } from 'vscode';
|
||||
import { getScheme, RequestService, FileType } from '../requests';
|
||||
import { FileSystemProvider, FileType } from '../requests';
|
||||
|
||||
export function getNodeFSRequestService(): RequestService {
|
||||
export function getNodeFileFS(): FileSystemProvider {
|
||||
function ensureFileUri(location: string) {
|
||||
if (getScheme(location) !== 'file') {
|
||||
if (!location.startsWith('file:')) {
|
||||
throw new Error('fileRequestService can only handle file URLs');
|
||||
}
|
||||
}
|
||||
return {
|
||||
getContent(location: string, encoding?: string) {
|
||||
ensureFileUri(location);
|
||||
return new Promise((c, e) => {
|
||||
const uri = Uri.parse(location);
|
||||
fs.readFile(uri.fsPath, encoding, (err, buf) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
c(buf.toString());
|
||||
|
||||
});
|
||||
});
|
||||
},
|
||||
stat(location: string) {
|
||||
ensureFileUri(location);
|
||||
return new Promise((c, e) => {
|
||||
|
||||
Reference in New Issue
Block a user