How to use the mz/fs.readdir function in mz

To help you get started, we’ve selected a few mz 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 pedromsilvapt / unicast / src / Extensions / MediaProviders / FileSystem / FileSystemMediaSource.ts View on Github external
streams.push( new FileSystemVideoMediaStream( file, this, metadata ) );

            // TODO Re-enable embedded subtitle streams
            // const subtitles = metadata.tracks.filter( track => track.type == 'subtitle' );

            // for ( let track of subtitles ) {
            //     // TODO Read metadata here and create embedded subtitle streams
            //     streams.push( new FileSystemEmbeddedSubtitleStream( this, `${file}?${track.index}`, this.source, track ) );
            // }

            const folder = path.dirname( file );

            const filePrefix = path.basename( file, path.extname( file ) );

            const otherFiles = await fs.readdir( folder );
            
            const matchingFiles = otherFiles
                .filter( file => file.startsWith( filePrefix ) )
                .filter( file => isSubtitle( file ) );

            for ( let file of matchingFiles ) {
                streams.push( new FileSystemSubtitlesMediaStream( path.join( folder, file ), this ) );
            }
        }

        if ( isSubtitle( file ) ) {
            streams.push( new FileSystemSubtitlesMediaStream( file, this ) );
        }

        return streams;
    }
github microsoft / vscode / test / tree / server.js View on Github external
async function getTree(fsPath, level) {
	const element = path.basename(fsPath);
	const stat = await fs.stat(fsPath);

	if (!stat.isDirectory() || element === '.git' || element === '.build' || level >= 3) {
		return { element };
	}

	const childNames = await fs.readdir(fsPath);
	const children = await Promise.all(childNames.map(async childName => await getTree(path.join(fsPath, childName), level + 1)));
	return { element, collapsible: true, collapsed: false, children };
}
github surf-build / surf / src / git-api.ts View on Github external
d('Opening index');
    let idx = await repo.index();
    await idx.read(1);

    let stat = await fs.stat(artifactDirOrFile);
    if (stat.isFile()) {
      d(`Adding artifact directly as file: ${artifactDirOrFile}}`);
      let tgt = path.join(targetDir, path.basename(artifactDirOrFile));
      sfs.copySync(artifactDirOrFile, tgt);

      d(`Adding artifact: ${tgt}`);
      await idx.addByPath(path.basename(artifactDirOrFile));
    } else {
      d('Reading artifacts directory');
      let artifacts = await fs.readdir(artifactDirOrFile);
      for (let entry of artifacts) {
        let tgt = path.join(targetDir, entry);
        sfs.copySync(path.join(artifactDirOrFile, entry), tgt);

        d(`Adding artifact: ${tgt}`);
        await idx.addByPath(entry);
      }
    }

    await idx.write();
    let oid = await idx.writeTree();
    let head = await Reference.nameToId(repo, 'HEAD');
    let parent = ds(await repo.getCommit(head));

    d(`Writing commit to gist`);
    let now = new Date();
github SynBioHub / synbiohub / lib / views / admin / backup.js View on Github external
function listBackups () {
  return fs.readdir(backupDir).then((files) => {
    const backupFiles = files.filter((filename) => {
      return filename[0] !== '.' && filename.indexOf('.bp') !== -1
    })

    const backups = {}

    backupFiles.forEach((filename) => {
      const date = filename.split('_')[2]

      if (backups[date] === undefined) {
        backups[date] = [ filename ]
      } else {
        backups[date].push(filename)
      }
    })
github erdemoflaz / as-bayraklari / index.js View on Github external
const fs = require('mz/fs');
const http = require('http');
const {Readable} = require('stream');
const colors = require('colors/safe');
const frames = [];

fs.readdir('./frames').then(data => {
  data.forEach(async frame => {
    const f = await fs.readFile(`./frames/${frame}`);
    frames.push(f.toString());
  })
});

const streamer = stream => {
  let index = 0;
  return setInterval(() => {
    if (index >= frames.length) index = 0; stream.push('\033[2J\033[H');
      stream.push(colors['red'](frames[index]));
      index++;
  }, 150);
}

const server = http.createServer((req, res) => {
github sourcegraph / sourcegraph / lsif / src / worker / processors / clean-failed-jobs.ts View on Github external
await logAndTraceCall(ctx, 'Cleaning failed jobs', async () => {
        const purgeFile = async (filename: string): Promise => {
            const stat = await fs.stat(filename)
            if (Date.now() - stat.mtimeMs >= settings.FAILED_JOB_MAX_AGE) {
                await fs.unlink(filename)
            }
        }

        for (const directory of [constants.TEMP_DIR, constants.UPLOADS_DIR]) {
            for (const filename of await fs.readdir(path.join(settings.STORAGE_ROOT, directory))) {
                await purgeFile(path.join(settings.STORAGE_ROOT, directory, filename))
            }
        }
    })
}
github decaffeinate / decaffeinate / src / cli.ts View on Github external
async function processDirectory(path: string): Promise {
    const children = await readdir(path);

    for (const child of children) {
      const childPath = join(path, child);
      const childStat = await stat(childPath);

      if (childStat.isDirectory()) {
        await processDirectory(childPath);
      } else if (options.modernizeJS) {
        if (child.endsWith('.js')) {
          await processPath(childPath);
        }
      } else if (child.endsWith('.coffee') || child.endsWith('.litcoffee') || child.endsWith('.coffee.md')) {
        await processPath(childPath);
      }
    }
  }
github sourcegraph / sourcegraph / lsif / src / server.ts View on Github external
async function moveDatabaseFilesToSubdir(): Promise {
    for (const filename of await fs.readdir(STORAGE_ROOT)) {
        if (filename.endsWith('.db')) {
            await fs.rename(path.join(STORAGE_ROOT, filename), path.join(STORAGE_ROOT, constants.DBS_DIR, filename))
        }
    }
}
github macacajs / macaca-datahub / app / service / database.js View on Github external
async importProjectRelated(baseDir) {
    const contents = await fs.readdir(baseDir);
    await Promise.all(contents.map(async content => {
      const constentPath = path.join(baseDir, content);
      const stat = await fs.stat(constentPath);
      if (stat.isFile()) {
        await this.importInterface(constentPath);
      }
      if (stat.isDirectory()) {
        await this.importScene(path.join(constentPath, 'scene'));
        await this.importSchema(path.join(constentPath, 'schema'));
      }
    }));
  }
github sourcegraph / sourcegraph / lsif / src / server / server.ts View on Github external
async function moveDatabaseFilesToSubdir(): Promise {
    for (const filename of await fs.readdir(settings.STORAGE_ROOT)) {
        if (filename.endsWith('.db')) {
            await fs.rename(
                path.join(settings.STORAGE_ROOT, filename),
                path.join(settings.STORAGE_ROOT, constants.DBS_DIR, filename)
            )
        }
    }
}