本文整理匯總了TypeScript中vs/base/node/pfs.readFile函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript readFile函數的具體用法?TypeScript readFile怎麽用?TypeScript readFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了readFile函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getColorsFromExtension
async function getColorsFromExtension(): Promise<{ [id: string]: string }> {
let extPath = getPathFromAmdModule(require, '../../../../../../extensions');
let extFolders = await pfs.readDirsInDir(extPath);
let result: { [id: string]: string } = Object.create(null);
for (let folder of extFolders) {
try {
let packageJSON = JSON.parse((await pfs.readFile(path.join(extPath, folder, 'package.json'))).toString());
let contributes = packageJSON['contributes'];
if (contributes) {
let colors = contributes['colors'];
if (colors) {
for (let color of colors) {
let colorId = color['id'];
if (colorId) {
result[colorId] = colorId['description'];
}
}
}
}
} catch (e) {
// ignore
}
}
return result;
}
示例2:
return _service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8_with_bom }).then(() => {
return pfs.readFile(resource.fsPath).then(data => {
assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), encodingLib.UTF8);
// Update content: PRESERVE BOM when using UTF-8
model.setValue('Please stay Bom');
return _service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8 }).then(() => {
return pfs.readFile(resource.fsPath).then(data => {
assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), encodingLib.UTF8);
// Update content: REMOVE BOM
model.setValue('Go away Bom');
return _service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8, overwriteEncoding: true }).then(() => {
return pfs.readFile(resource.fsPath).then(data => {
assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);
// Update content: BOM comes not back
model.setValue('Do not come back Bom');
return _service.updateContent(resource, model.createSnapshot(), { encoding: encodingLib.UTF8 }).then(() => {
return pfs.readFile(resource.fsPath).then(data => {
assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);
model.dispose();
_service.dispose();
});
});
});
});
});
});
});
});
示例3: resolveCommonProperties
export async function resolveCommonProperties(commit: string | undefined, version: string | undefined, machineId: string | undefined, installSourcePath: string, product?: string): Promise<{ [name: string]: string | undefined; }> {
const result: { [name: string]: string | undefined; } = Object.create(null);
// __GDPR__COMMON__ "common.machineId" : { "endPoint": "MacAddressHash", "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight" }
result['common.machineId'] = machineId;
// __GDPR__COMMON__ "sessionID" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['sessionID'] = uuid.generateUuid() + Date.now();
// __GDPR__COMMON__ "commitHash" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['commitHash'] = commit;
// __GDPR__COMMON__ "version" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['version'] = version;
// __GDPR__COMMON__ "common.platformVersion" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.platformVersion'] = (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
// __GDPR__COMMON__ "common.platform" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.platform'] = Platform.PlatformToString(Platform.platform);
// __GDPR__COMMON__ "common.nodePlatform" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.nodePlatform'] = process.platform;
// __GDPR__COMMON__ "common.nodeArch" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.nodeArch'] = process.arch;
// __GDPR__COMMON__ "common.product" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.product'] = product || 'desktop';
// dynamic properties which value differs on each call
let seq = 0;
const startTime = Date.now();
Object.defineProperties(result, {
// __GDPR__COMMON__ "timestamp" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
'timestamp': {
get: () => new Date(),
enumerable: true
},
// __GDPR__COMMON__ "common.timesincesessionstart" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
'common.timesincesessionstart': {
get: () => Date.now() - startTime,
enumerable: true
},
// __GDPR__COMMON__ "common.sequence" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
'common.sequence': {
get: () => seq++,
enumerable: true
}
});
if (process.platform === 'linux' && process.env.SNAP && process.env.SNAP_REVISION) {
// __GDPR__COMMON__ "common.snap" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.snap'] = 'true';
}
try {
const contents = await readFile(installSourcePath, 'utf8');
// __GDPR__COMMON__ "common.source" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.source'] = contents.slice(0, 30);
} catch (error) {
// ignore error
}
return result;
}
示例4: resolveCommonProperties
export function resolveCommonProperties(commit: string, version: string, machineId: string, installSourcePath: string): TPromise<{ [name: string]: string; }> {
const result: { [name: string]: string; } = Object.create(null);
// {{SQL CARBON EDIT}}
// __GDPR__COMMON__ "common.machineId" : { "endPoint": "MacAddressHash", "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight" }
// result['common.machineId'] = machineId;
result['common.machineId'] = '';
// // __GDPR__COMMON__ "sessionID" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['sessionID'] = uuid.generateUuid() + Date.now();
result['sessionID'] = '';
// __GDPR__COMMON__ "commitHash" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['commitHash'] = commit;
// __GDPR__COMMON__ "version" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['version'] = version;
// __GDPR__COMMON__ "common.platformVersion" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.platformVersion'] = (os.release() || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3');
// __GDPR__COMMON__ "common.platform" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.platform'] = Platform.Platform[Platform.platform];
// __GDPR__COMMON__ "common.nodePlatform" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.nodePlatform'] = process.platform;
// __GDPR__COMMON__ "common.nodeArch" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.nodeArch'] = process.arch;
// {{SQL CARBON EDIT}}
result['common.application.name'] = product.nameLong;
// dynamic properties which value differs on each call
let seq = 0;
const startTime = Date.now();
Object.defineProperties(result, {
// __GDPR__COMMON__ "timestamp" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
'timestamp': {
get: () => new Date(),
enumerable: true
},
// __GDPR__COMMON__ "common.timesincesessionstart" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
'common.timesincesessionstart': {
get: () => Date.now() - startTime,
enumerable: true
},
// __GDPR__COMMON__ "common.sequence" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
'common.sequence': {
get: () => seq++,
enumerable: true
}
});
return readFile(installSourcePath, 'utf8').then(contents => {
// __GDPR__COMMON__ "common.source" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.source'] = contents.slice(0, 30);
return result;
}, error => {
return result;
});
}
示例5: readFile
export function readRawMapping<T>(file: string): TPromise<T> {
return readFile(require.toUrl(`vs/workbench/services/keybinding/test/${file}.js`)).then((buff) => {
let contents = buff.toString();
let func = new Function('define', contents);
let rawMappings: T = null;
func(function (value) {
rawMappings = value;
});
return rawMappings;
});
}
示例6: fileExists
fileExists(file).then(exists => {
if (!exists) {
return;
}
readFile(file).then(b => {
const contents = b.toString();
if (contents.indexOf('NAME=Fedora') >= 0) {
isFedora = true;
}
});
});
示例7: readFile
export function readRawMapping<T>(file: string): Promise<T> {
return readFile(getPathFromAmdModule(require, `vs/workbench/services/keybinding/test/${file}.js`)).then((buff) => {
let contents = buff.toString();
let func = new Function('define', contents);
let rawMappings: T | null = null;
func(function (value: T) {
rawMappings = value;
});
return rawMappings!;
});
}
示例8: fileExists
fileExists(file).then(exists => {
if (!exists) {
return;
}
readFile(file).then(b => {
const contents = b.toString();
if (/NAME="?Fedora"?/.test(contents)) {
isFedora = true;
} else if (/NAME="?Ubuntu"?/.test(contents)) {
isUbuntu = true;
}
});
});
示例9: assertMapping
export function assertMapping(writeFileIfDifferent: boolean, mapper: IKeyboardMapper, file: string): TPromise<void> {
const filePath = require.toUrl(`vs/workbench/services/keybinding/test/${file}`);
return readFile(filePath).then((buff) => {
let expected = buff.toString();
const actual = mapper.dumpDebugInfo();
if (actual !== expected && writeFileIfDifferent) {
writeFile(filePath, actual);
}
assert.deepEqual(actual.split(/\r\n|\n/), expected.split(/\r\n|\n/));
});
}