本文整理汇总了TypeScript中vs/workbench/services/files/node/fileService.FileService.updateContent方法的典型用法代码示例。如果您正苦于以下问题:TypeScript FileService.updateContent方法的具体用法?TypeScript FileService.updateContent怎么用?TypeScript FileService.updateContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/workbench/services/files/node/fileService.FileService
的用法示例。
在下文中一共展示了FileService.updateContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
return service.resolveContent(resource).then(c => {
fs.writeFileSync(resource.fsPath, 'Updates Incoming!');
return service.updateContent(resource, c.value, { etag: c.etag, mtime: c.mtime - 1000 }).then(null, (e: FileOperationError) => {
assert.equal(e.fileOperationResult, FileOperationResult.FILE_MODIFIED_SINCE);
});
});
示例2:
fs.readFile(resource.fsPath, (error, data) => {
assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), encodingLib.UTF8);
// Update content: PRESERVE BOM when using UTF-8
_service.updateContent(resource, 'Please stay Bom', { encoding: encodingLib.UTF8 }).done(() => {
fs.readFile(resource.fsPath, (error, data) => {
assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), encodingLib.UTF8);
// Update content: REMOVE BOM
_service.updateContent(resource, 'Go away Bom', { encoding: encodingLib.UTF8, overwriteEncoding: true }).done(() => {
fs.readFile(resource.fsPath, (error, data) => {
assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);
// Update content: BOM comes not back
_service.updateContent(resource, 'Do not come back Bom', { encoding: encodingLib.UTF8 }).done(() => {
fs.readFile(resource.fsPath, (error, data) => {
assert.equal(encodingLib.detectEncodingByBOMFromBuffer(data, 512), null);
_service.dispose();
done();
});
});
});
});
});
});
});
示例3: FileService
fs.readFile(resource.fsPath, (error, data) => {
assert.equal(encoding.detectEncodingByBOMFromBuffer(data, 512), encoding.UTF8);
_service.dispose();
_service = new FileService(_testDir, null, {
bom: BOMConfiguration.REMOVE,
disableWatcher: true
});
// Update content: BOM => REMOVE
_service.updateContent(resource, 'Hello Bom').done(() => {
fs.readFile(resource.fsPath, (error, data) => {
assert.equal(encoding.detectEncodingByBOMFromBuffer(data, 512), null);
_service.dispose();
_service = new FileService(_testDir, null, {
bom: BOMConfiguration.PRESERVE,
disableWatcher: true
});
// Update content: BOM => PRESERVE
_service.updateContent(resource, 'Hello Bom').done(() => {
fs.readFile(resource.fsPath, (error, data) => {
assert.equal(encoding.detectEncodingByBOMFromBuffer(data, 512), null);
_service.dispose();
done();
});
});
});
});
});
示例4:
service.resolveContent(resource).done(c => {
c.charset = charset;
return service.updateContent(c.resource, c.value, { charset: charset }).then(c => {
return service.resolveContent(resource).then(c => {
assert.equal(c.charset, charset);
done();
});
});
});