How to use fs-observable - 10 common examples

To help you get started, we’ve selected a few fs-observable 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 nteract / nteract / applications / desktop / src / notebook / epics / loading.ts View on Github external
switchMap(action => {
      const filepath = action.payload.filepath;

      return forkJoin(
        readFileObservable(filepath),
        statObservable(filepath),
        // Project onto the Contents API response
        (content: Buffer, stat: fs.Stats): contents.IContent =>
          createContentsResponse(filepath, stat, content)
      ).pipe(
        // Timeout after one minute
        timeout(60 * 1000),
        map((model: contents.IContent<"notebook">) => {
          if (model.type !== "notebook") {
            throw new Error(
              "Attempted to load a non-notebook type from desktop"
            );
          }
          if (model.content === null) {
            throw new Error("No content loaded for notebook");
          }
github nteract / nteract / applications / desktop / src / main / index.ts View on Github external
mergeMap(() =>
    // Create all the directories we need in parallel
    forkJoin(
      // Ensure the runtime Dir is setup for kernels
      mkdirpObservable(jupyterPaths.runtimeDir()),
      // Ensure the config directory is all set up
      mkdirpObservable(jupyterConfigDir)
    )
  ),
github nteract / nteract / applications / desktop / src / main / index.ts View on Github external
mergeMap(() =>
    // Create all the directories we need in parallel
    forkJoin(
      // Ensure the runtime Dir is setup for kernels
      mkdirpObservable(jupyterPaths.runtimeDir()),
      // Ensure the config directory is all set up
      mkdirpObservable(jupyterConfigDir)
    )
  ),
github nteract / nteract / applications / desktop / src / notebook / epics / loading.ts View on Github external
switchMap(action => {
      const filepath = action.payload.filepath;

      return forkJoin(
        readFileObservable(filepath),
        statObservable(filepath),
        // Project onto the Contents API response
        (content: Buffer, stat: fs.Stats): contents.IContent =>
          createContentsResponse(filepath, stat, content)
      ).pipe(
        // Timeout after one minute
        timeout(60 * 1000),
        map((model: contents.IContent<"notebook">) => {
          if (model.type !== "notebook") {
            throw new Error(
              "Attempted to load a non-notebook type from desktop"
            );
          }
          if (model.content === null) {
            throw new Error("No content loaded for notebook");
          }
github nteract / nteract / applications / desktop / src / notebook / epics / saving.ts View on Github external
return of(
          actions.saveFailed({
            contentRef: action.payload.contentRef,
            error: new Error("no notebook loaded to save")
          })
        );
      }

      const filepath = content.filepath;
      const appVersion = selectors.appVersion(state);
      const notebook = stringifyNotebook(
        toJS(
          model.notebook.setIn(["metadata", "nteract", "version"], appVersion)
        )
      );
      return writeFileObservable(filepath, notebook).pipe(
        map(() => {
          if (process.platform !== "darwin") {
            const notificationSystem = selectors.notificationSystem(
              state$.value
            );
            notificationSystem.addNotification({
              autoDismiss: 2,
              level: "success",
              title: "Save successful!"
            });
          }
          return actions.saveFulfilled({
            contentRef: action.payload.contentRef,
            model: {
              last_modified: new Date()
            }
github nteract / nteract / applications / desktop / src / notebook / epics / config.ts View on Github external
mergeMap(() =>
      writeFileObservable(
        CONFIG_FILE_PATH,
        JSON.stringify(state$.value.config.toJS())
      ).pipe(map(actions.doneSavingConfig))
    )
github nteract / nteract / applications / desktop / src / main / cli.ts View on Github external
const installShellCommandsObservable = (
  exe: string,
  rootDir: string,
  binDir: string
): Observable => {
  if (process.platform === "win32") {
    return setWinPathObservable(exe, rootDir, binDir);
  }
  const envFile = join(binDir, "nteract-env");
  return writeFileObservable(
    envFile,
    `NTERACT_EXE="${exe}"\nNTERACT_DIR="${rootDir}"`
  ).pipe(
    mergeMap(() => {
      const target = join(binDir, "nteract.sh");
      return createSymlinkObservable(target, "/usr/local/bin/nteract").pipe(
        catchError(() => {
          if (!process.env.HOME) {
            throw new Error("HOME not defined");
          }
          const dest = join(process.env.HOME, ".local/bin/nteract");
          return createSymlinkObservable(target, dest);
        })
      );
    })
  );
github nteract / nteract / applications / desktop / src / main / index.ts View on Github external
catchError(err => {
        if (err.code === "ENOENT") {
          return writeFileObservable(
            nteractConfigFilename,
            JSON.stringify({
              theme: "light"
            })
          );
        }
        throw err;
      })
    )
github nteract / nteract / applications / desktop / src / main / cli.js View on Github external
const installShellCommandsObservable = (
  exe: string,
  rootDir: string,
  binDir: string
) => {
  if (process.platform === "win32") {
    return setWinPathObservable(exe, rootDir, binDir);
  }
  const envFile = join(binDir, "nteract-env");
  return writeFileObservable(
    envFile,
    `NTERACT_EXE="${exe}"\nNTERACT_DIR="${rootDir}"`
  ).pipe(
    mergeMap(() => {
      const target = join(binDir, "nteract.sh");
      return createSymlinkObservable(target, "/usr/local/bin/nteract").pipe(
        catchError(() => {
          const dest = join(process.env.HOME, ".local/bin/nteract");
          return createSymlinkObservable(target, dest);
        })
      );
    })
  );
};
github nteract / nteract / applications / desktop / src / main / cli.ts View on Github external
catchError(() => {
          if (!process.env.HOME) {
            throw new Error("HOME not defined");
          }
          const dest = join(process.env.HOME, ".local/bin/nteract");
          return createSymlinkObservable(target, dest);
        })
      );