提交 022325bf 编写于 作者: J Johannes Rieken

much more, del, streaming, etc

上级 e9ac57ee
......@@ -133,17 +133,17 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
throw new Error();
}
const emitter = new Emitter<URI>();
const provider = {
onDidChange: emitter.event,
read: (resource: URI) => {
return this._proxy.$resolveFile(handle, resource);
},
write: (resource: URI, value: string) => {
return this._proxy.$storeFile(handle, resource, value);
},
stat: () => null,
readdir: () => null
};
// const provider = {
// onDidChange: emitter.event,
// read: (resource: URI) => {
// return this._proxy.$resolveFile(handle, resource);
// },
// write: (resource: URI, value: string) => {
// return this._proxy.$storeFile(handle, resource, value);
// },
// stat: () => null,
// readdir: () => null
// };
const searchProvider = {
search: (query: ISearchQuery) => {
if (query.type !== QueryType.File) {
......@@ -159,7 +159,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
}
};
const registrations = combinedDisposable([
this._fileService.registerProvider(authority, provider),
// this._fileService.registerProvider(authority, provider),
this._searchService.registerSearchResultProvider(searchProvider),
]);
this._provider.set(handle, [registrations, emitter]);
......
......@@ -13,9 +13,10 @@ import { ninvoke } from 'vs/base/common/async';
import { TPromise } from 'vs/base/common/winjs.base';
import { Readable } from 'stream';
import { join } from 'path';
import { IStat } from 'vs/workbench/services/files/electron-browser/remoteFileService';
import { IStat, IRemoteFileSystemProvider } from 'vs/workbench/services/files/electron-browser/remoteFileService';
import { IProgress } from 'vs/platform/progress/common/progress';
export class FtpFileSystemProvider {
export class FtpFileSystemProvider implements IRemoteFileSystemProvider {
private _connection: JSFtp;
......@@ -23,9 +24,7 @@ export class FtpFileSystemProvider {
constructor() {
this._connection = new JSFtp({
host: 'waws-prod-db3-029.ftp.azurewebsites.windows.net',
user: 'performanto-slack-updater\\riejo-test',
pass: 'Z0llikon'
host: 'waws-prod-db3-029.ftp.azurewebsites.windows.net'
});
this._connection.keepAlive(1000 * 5);
}
......@@ -69,26 +68,27 @@ export class FtpFileSystemProvider {
});
}
write(resource: URI, content: string): TPromise<void> {
return ninvoke(this._connection, this._connection.put, Buffer.from(content, 'utf8'), resource.path);
}
read(resource: URI): TPromise<string> {
read(resource: URI, progress: IProgress<Uint8Array>): TPromise<void> {
return ninvoke<Readable>(this._connection, this._connection.get, resource.path).then(stream => {
return new TPromise<string>((resolve, reject) => {
let str = '';
stream.on('data', function (d) {
str += d.toString();
});
stream.on('close', function (hadErr) {
return new TPromise<void>((resolve, reject) => {
stream.on('data', d => progress.report(<any>d));
stream.on('close', hadErr => {
if (hadErr) {
reject(hadErr);
} else {
resolve(str);
resolve(undefined);
}
});
stream.resume();
});
});
}
write(resource: URI, content: string): TPromise<void> {
return ninvoke(this._connection, this._connection.put, Buffer.from(content, 'utf8'), resource.path);
}
del(resource: URI): TPromise<void> {
return ninvoke(this._connection, this._connection.raw, 'DELE', [resource.path]);
}
}
......@@ -24,6 +24,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import { groupBy, isFalsyOrEmpty } from 'vs/base/common/arrays';
import { compare } from 'vs/base/common/strings';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { IProgress, Progress } from 'vs/platform/progress/common/progress';
export interface IStat {
......@@ -41,7 +42,7 @@ function toIFileStat(provider: IRemoteFileSystemProvider, stat: IStat, recurse:
name: basename(stat.resource.path),
mtime: stat.mtime,
size: stat.size,
etag: stat.mtime.toString(3) + stat.size.toString(7),
etag: stat.mtime.toString(29) + stat.size.toString(31),
};
if (!stat.isDirectory) {
......@@ -72,8 +73,9 @@ export interface IRemoteFileSystemProvider {
onDidChange?: Event<URI>;
stat(resource: URI): TPromise<IStat>;
readdir(resource: URI): TPromise<IStat[]>;
read(resource: URI, progress: IProgress<Uint8Array>): TPromise<void>;
write(resource: URI, content: string): TPromise<void>;
read(resource: URI): TPromise<string>;
del(resource: URI): TPromise<void>;
}
export class RemoteFileService extends FileService {
......@@ -99,9 +101,7 @@ export class RemoteFileService extends FileService {
// public rename(resource: URI, newName: string): TPromise<IFileStat, any> {
// throw new Error("Method not implemented.");
// }
// public del(resource: URI, useTrash?: boolean): TPromise<void, any> {
// throw new Error("Method not implemented.");
// }
private readonly _provider = new Map<string, IRemoteFileSystemProvider>();
......@@ -212,16 +212,20 @@ export class RemoteFileService extends FileService {
return super.resolveStreamContent(resource, options);
}
private _doResolveContent(provider: IRemoteFileSystemProvider, resource: URI): TPromise<IContent> {
private async _doResolveContent(provider: IRemoteFileSystemProvider, resource: URI): TPromise<IContent> {
return provider.stat(resource).then(stat => {
return provider.read(resource).then(value => {
return <any>{
...stat,
value,
};
});
});
const chunks: Uint8Array[] = [];
await provider.read(resource, new Progress<Uint8Array>(chunk => chunks.push(chunk)));
const stat = await toIFileStat(provider, await provider.stat(resource), false);
return {
value: [].concat(...chunks).toString(),
resource: stat.resource,
name: stat.name,
etag: stat.etag,
mtime: stat.mtime,
encoding: this.getEncoding(resource)
};
}
// --- saving
......@@ -252,4 +256,14 @@ export class RemoteFileService extends FileService {
}, 0);
return result;
}
// --- delete
del(resource: URI, useTrash?: boolean): TPromise<void> {
const provider = this._provider.get(resource.scheme);
if (provider) {
return provider.del(resource);
}
return super.del(resource, useTrash);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册