Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
function exec(
command: string,
options?: {
encoding?: string | BufferEncoding | null | 'buffer';
cwd?: string;
env?: NodeJS.ProcessEnv;
shell?: string;
timeout?: number;
maxBuffer?: number;
killSignal?: string;
uid?: number;
gid?: number;
windowsHide?: boolean;
}
): Observable<[stdout: string | Buffer, stderr: string | Buffer]>;exec('"/path/to/test file/test.sh" arg1 arg2').subscribe();
// Double quotes are used so that the space in the path is not interpreted as
// a delimiter of multiple arguments.
exec('echo "The \\$HOME variable is $HOME"').subscribe();
// The $HOME variable is escaped in the first instance, but not in the second.import { exec } from '@rxnode/child_process';
exec('cat *.js missing_file | wc -l').subscribe({
next([stdout, stderr]) {
console.log(`stdout: ${stdout}`);
console.error(`stderr: ${stderr}`);
},
error(error) {
console.error(`exec error: ${error}`);
},
});function execFile(
file: string,
args?: readonly string[],
options?: {
encoding?: string | null | BufferEncoding;
cwd?: string;
env?: NodeJS.ProcessEnv;
timeout?: number;
maxBuffer?: number;
killSignal?: string;
uid?: number;
gid?: number;
windowsHide?: boolean;
windowsVerbatimArguments?: boolean;
shell?: boolean | string;
}
): Observable<[stdout: string | Buffer, stderr: string | Buffer]>;import { execFile } from '@rxnode/child_process';
execFile('node', ['--version']).subscribe({
next([stdout, stderr]) {
console.log(stdout);
},
error(error) {
console.error(`exec error: ${error}`);
},
});import { readFile, writeFile } from 'fs';
readFile('src/some-file.js', (error, data) => {
if (error) {
console.error(error);
return;
}
writeFile('src/some-file.js', data, (error) => {
if (error) {
console.error(error);
return;
}
console.log('Success!');
});
});
import * as fs from 'fs';
import { promisify } from 'util';
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
readFile('src/some-file.js')
.then((data) => writeFile('src/some-file.js', data))
.then(() => {
console.log('Success!');
})
.cacth(console.error);import * as fs from 'fs';
import { bindNodeCallback, Observable } from 'rxjs';
import { mergeMap, switchMap } from 'rxjs/operators';
const readFile = bindNodeCallback(fs.readFile);
const writeFile = bindNodeCallback(fs.writeFile);
let files: Observable<string>;
const LIMIT = 2;
files
.pipe(
mergeMap(
(file) => someProcessWithFiles(file),
LIMIT
)
.subscribe({
complete() {
console.log('Complete!');
},
});import { readFile, writeFile } from '@rxnode/fs';
import { switchMap } from 'rxjs/operators';
readFile('src/some-file.js')
.pipe(switchMap((data) => writeFile('src/some-file.js', data)))
.subscribe({
complete() {
console.log('Complete!');
},
});import { createServer } from '@rxnode/http';
const server = createServer();
server.subscribe(([req, res]) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('okay');
});
server.listen(8080).subscribe();npm run lint
npm run build
npm run testfunction watchify<A extends Arguments, R extends Results>(
fn: (...args: [...A, Callback<R>]) => any,
{ closeOnUnsubscribe: closeOnUnsubscribe }?: { closeOnUnsubscribe?: boolean }
): (...args: A) => Observable<VoidOrItemOrItems<R>>;import { open } from '@rxnode/fs';
open('myfile', 'wx').subscribe((fd) => writeMyData(fd));import { access } from '@rxnode/fs';
const file = 'package.json';
// Check if the file exists in the current directory.
access(file, fs.constants.F_OK).subscribe({
next() {
console.log(`${file} exists`);
},
error(err) {
console.log(`${file} does not exist`);
},
});
// Check if the file is readable.
access(file, fs.constants.R_OK).subscribe({
next() {
console.log(`${file} is readable`);
},
error(err) {
console.log(`${file} is not readable`);
},
});
// Check if the file is writable.
access(file, fs.constants.W_OK).subscribe({
next() {
console.log(`${file} is writable`);
},
error(err) {
console.log(`${file} is not writable`);
},
});
// Check if the file exists in the current directory, and if it is writable.
access(file, fs.constants.F_OK | fs.constants.W_OK).subscribe({
next() {
console.log(`${file} exists, and it is writable`);
},
error(err) {
console.error(
`${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`
);
},
});import { access, open } from '@rxnode/fs';
access('myfile').subscribe({
next() {
console.error('myfile already exists');
},
error() {
open('myfile', 'wx').subscribe((fd) => {
writeMyData(fd);
});
},
});import { access, open } from '@rxnode/fs';
access('myfile').subscribe(() => {
open('myfile', 'r').subscribe((fb) => readMyData(fd));
});import { open } from '@rxnode/fs';
open('myfile', 'r').subscribe((fd) => {
readMyData(fd);
});