How to use the @theia/core/lib/node/file-uri.FileUri.fsPath function in @theia/core

To help you get started, we’ve selected a few @theia/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / mini-browser / src / node / mini-browser-endpoint.ts View on Github external
respond(statWithContent: FileStatWithContent, response: Response): MaybePromise {
        // https://stackoverflow.com/questions/11598274/display-pdf-in-browser-using-express-js
        const encodeRFC5987ValueChars = (input: string) =>
            encodeURIComponent(input).
                // Note that although RFC3986 reserves "!", RFC5987 does not, so we do not need to escape it.
                replace(/['()]/g, escape). // i.e., %27 %28 %29
                replace(/\*/g, '%2A').
                // The following are not required for percent-encoding per RFC5987, so we can allow for a little better readability over the wire: |`^.
                replace(/%(?:7C|60|5E)/g, unescape);

        const fileName = FileUri.create(statWithContent.stat.uri).path.base;
        fs.readFile(FileUri.fsPath(statWithContent.stat.uri), (error, data) => {
            if (error) {
                throw error;
            }
            // Change `inline` to `attachment` if you would like to force downloading the PDF instead of previewing in the browser.
            response.setHeader('Content-disposition', `inline; filename*=UTF-8''${encodeRFC5987ValueChars(fileName)}`);
            response.contentType('application/pdf');
            response.send(data);
        });
        return response;
    }
github eclipse-theia / theia / packages / plugin-dev / src / node / hosted-instance-manager.ts View on Github external
private async doRun(pluginUri: URI, port?: number, debugConfig?: DebugConfiguration): Promise {
        if (this.isPluginRunning) {
            this.hostedPluginSupport.sendLog({ data: 'Hosted plugin instance is already running.', type: LogType.Info });
            throw new Error('Hosted instance is already running.');
        }

        let command: string[];
        let processOptions: cp.SpawnOptions;
        if (pluginUri.scheme === 'file') {
            processOptions = { ...PROCESS_OPTIONS };
            // get filesystem path that work cross operating systems
            processOptions.env.HOSTED_PLUGIN = FileUri.fsPath(pluginUri.toString());

            // Disable all the other plugins on this instance
            processOptions.env.THEIA_PLUGINS = '';
            command = await this.getStartCommand(port, debugConfig);
        } else {
            throw new Error('Not supported plugin location: ' + pluginUri.toString());
        }

        this.instanceUri = await this.postProcessInstanceUri(
            await this.runHostedPluginTheiaInstance(command, processOptions));
        this.pluginUri = pluginUri;
        // disable redirect to grab the release
        this.instanceOptions = {
            followRedirect: false
        };
        this.instanceOptions = await this.postProcessInstanceOptions(this.instanceOptions);
github eclipse-theia / theia / packages / preferences / src / node / json-preference-server.spec.ts View on Github external
prefServer.setClient({
                    onDidChangePreference(event) {
                        for (const change of event.changes) {
                            expect(change.newValue).to.be.equal(true);
                            done();
                        }
                    }
                });
            });

            const fileContent = '{ "showLineNumbers": true }';

            // Modify the content.
            fs.writeFileSync(FileUri.fsPath(preferenceFileUri), fileContent);

            let { content } = await helper.getFS().resolveContent(FileUri.fsPath(preferenceFileUri));
            expect(content).to.be.equal(fileContent);

            helper.getWatcher().fireEvents(
                {
                    changes: [{
                        uri: preferenceFileUri.toString(),
                        type: 0
                    }]
                }
            );

            return promise;

        }).timeout(10000);
    });
github eclipse-theia / theia / packages / git / src / node / dugite-git.spec.ts View on Github external
it('modified in working directory (nested)', async () => {
            const repositoryPath = FileUri.fsPath(repository!.localUri);
            fs.writeFileSync(path.join(repositoryPath, 'folder', 'C.txt'), 'new content');
            expect(fs.readFileSync(path.join(repositoryPath, 'folder', 'C.txt'), { encoding: 'utf8' })).to.be.equal('new content');
            const content = await git!.show(repository!, FileUri.create(path.join(repositoryPath, 'folder', 'C.txt')).toString(), { commitish: 'HEAD' });
            expect(content).to.be.equal('C');
        });
github eclipse-theia / theia / packages / preferences / src / common / compound-preference-server.spec.ts View on Github external
before(() => {
    chai.should();
    chai.use(chaiAsPromised);
    chai.config.showDiff = true;
    chai.config.includeStack = true;

    const rootUri = FileUri.create(track.mkdirSync());
    preferenceFileUri = rootUri.resolve(preferencePath);
    fs.mkdirSync(FileUri.fsPath(rootUri.resolve('.theia')));
    fs.writeFileSync(FileUri.fsPath(preferenceFileUri), '');

    const jsonPrefServer = helper.createJsonPrefServer(preferenceFileUri);
    compoundPrefServer = new CompoundPreferenceServer(jsonPrefServer);
});
github eclipse-theia / theia / packages / preferences / src / common / compound-preference-server.spec.ts View on Github external
before(() => {
    chai.should();
    chai.use(chaiAsPromised);
    chai.config.showDiff = true;
    chai.config.includeStack = true;

    const rootUri = FileUri.create(track.mkdirSync());
    preferenceFileUri = rootUri.resolve(preferencePath);
    fs.mkdirSync(FileUri.fsPath(rootUri.resolve('.theia')));
    fs.writeFileSync(FileUri.fsPath(preferenceFileUri), '');

    const jsonPrefServer = helper.createJsonPrefServer(preferenceFileUri);
    compoundPrefServer = new CompoundPreferenceServer(jsonPrefServer);
});
github eclipse-theia / theia / packages / git / src / node / dugite-git.spec.ts View on Github external
function toPathSegment(repository: Repository, uri: string): string {
    return upath.relative(FileUri.fsPath(repository.localUri), FileUri.fsPath(uri));
}
github eclipse-theia / theia / packages / filesystem / src / node / download / file-download-endpoint.ts View on Github external
app.get('/file', (request, response) => {
            const uri = url.parse(request.url).query;
            if (!uri) {
                response.status(400).send('invalid uri');
                return;
            }
            const fsPath = FileUri.fsPath(decodeURIComponent(uri));
            response.sendFile(fsPath);
        });
    }
github eclipse-theia / theia / packages / git / src / node / dugite-git.ts View on Github external
private getFsPath(repository: Repository | string): string {
        const uri = typeof repository === 'string' ? repository : repository.localUri;
        return FileUri.fsPath(uri);
    }
github eclipse-theia / theia / packages / filesystem / src / node / node-file-upload.ts View on Github external
constructor(
        readonly uri: string,
        readonly size: number
    ) {
        this.fsPath = FileUri.fsPath(uri);
        this.id = 'theia_upload_' + crypto.randomBytes(16).toString('hex');
        this.uploadPath = path.join(path.dirname(this.fsPath), this.id);
    }