All Projects → manidlou → Node Klaw Sync

manidlou / Node Klaw Sync

Licence: mit
Node.js recursive synchronous fast file system walker

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Klaw Sync

Write
Write data to the file system, creating any intermediate directories if they don't already exist. Used by flat-cache and many others!
Stars: ✭ 68 (-39.29%)
Mutual labels:  sync, fs
Fork Sync
🔄 Github action to sync your forks
Stars: ✭ 99 (-11.61%)
Mutual labels:  sync
Zbox
Zero-details, privacy-focused in-app file system.
Stars: ✭ 1,185 (+958.04%)
Mutual labels:  fs
Canal mysql nosql sync
基于canal 的 mysql 与 redis/memcached/mongodb 的 nosql 数据实时同步方案 案例 demo canal client
Stars: ✭ 1,254 (+1019.64%)
Mutual labels:  sync
Vuex Multi Tab State
💾🔗🖥️ Share, synchronize and persist state between multiple tabs with this plugin for Vuex. TypeScript types included.
Stars: ✭ 77 (-31.25%)
Mutual labels:  sync
Crowdin Cli
A command-line client for the Crowdin API
Stars: ✭ 89 (-20.54%)
Mutual labels:  sync
Sync Glitch Cli
🎏 Sync changes in your GitHub repository to glitch.com
Stars: ✭ 69 (-38.39%)
Mutual labels:  sync
Electron Storage
Simply save/load json files to/from file system in electron applications
Stars: ✭ 109 (-2.68%)
Mutual labels:  fs
Entitas Sync Framework
Networking framework for Entitas ECS. Targeted at turnbased games or other slow-paced genres.
Stars: ✭ 98 (-12.5%)
Mutual labels:  sync
Vault
Easy persistence of Contentful data for Android over SQLite.
Stars: ✭ 80 (-28.57%)
Mutual labels:  sync
Railschat
Real-time Rails-based Webchat for Instant Messaging (实时Web聊天室)
Stars: ✭ 81 (-27.68%)
Mutual labels:  sync
Etebase Rs
A Rust client library for Etebase
Stars: ✭ 78 (-30.36%)
Mutual labels:  sync
S3fs
S3 FileSystem (fs.FS) implementation
Stars: ✭ 93 (-16.96%)
Mutual labels:  fs
Git Repo Watcher
A simple bash script to watch a git repository and pull upstream changes if needed.
Stars: ✭ 73 (-34.82%)
Mutual labels:  sync
Webtranslateit
A CLI to sync locale files with webtranslateit.com.
Stars: ✭ 102 (-8.93%)
Mutual labels:  sync
Wakatime Sync
Update Wakatime summary data to your gist every day
Stars: ✭ 73 (-34.82%)
Mutual labels:  sync
Calendarsyncplus
This utility synchronizes Calendar entries between different calendar providers (Apps like Outlook,Services EWS/Google/Live).
Stars: ✭ 80 (-28.57%)
Mutual labels:  sync
Go Storage
An application-oriented unified storage layer for Golang.
Stars: ✭ 87 (-22.32%)
Mutual labels:  fs
Php K8s
PHP K8s is a PHP handler for the Kubernetes Cluster API, helping you handling the individual Kubernetes resources directly from PHP, like viewing, creating, updating or deleting resources.
Stars: ✭ 111 (-0.89%)
Mutual labels:  sync
Unifile
Unified access to cloud storage services through a simple web API.
Stars: ✭ 105 (-6.25%)
Mutual labels:  fs

node-klaw-sync

npm Package Build Status windows Build status JavaScript Style Guide Known Vulnerabilities

klaw-sync is a Node.js recursive and fast file system walker, which is the synchronous counterpart of klaw. It lists all files and directories inside a directory recursively and returns an array of objects that each object has two properties: path and stats. path is the full path of the file or directory and stats is an instance of fs.Stats.

Install

npm i klaw-sync

Usage

klawSync(directory[, options])

  • directory <String>
  • options <Object> (optional)
    • nodir <Boolean> default: undefined
      • return only files (ignore directories).
    • nofile <Boolean> default: undefined
      • return only directories (ignore files).
    • depthLimit: <Number> default: -1
      • the number of times to recurse before stopping. -1 for unlimited.
    • fs: <Object> default: graceful-fs
      • custom fs, useful when mocking fs object.
    • filter <Function> default: undefined
      • function that gets one argument fn({path: '', stats: {}}) and returns true to include or false to exclude the item.
    • traverseAll <Boolean> default: undefined
      • traverse all subdirectories, regardless of filter option. This can be useful when you have a filter function and still want to traverse all subdirectories even if your filter function doesn't pass for some directories.
  • Return: <Array<Object>> [{path: '', stats: {}}]

Examples

const klawSync = require('klaw-sync')

const paths = klawSync('/some/dir')
// paths = [{path: '/some/dir/dir1', stats: {}}, {path: '/some/dir/file1', stats: {}}]

catch error

const klawSync = require('klaw-sync')

let paths
try {
  paths = klawSync('/some/dir')
} catch (er) {
  console.error(er)
}
console.dir(paths)

files only

const klawSync = require('klaw-sync')

const files = klawSync('/some/dir', {nodir: true})
// files = [{path: '/some/dir/file1', stats: {}}, {path: '/some/dir/file2', stats: {}}]

directories only

const klawSync = require('klaw-sync')

const dirs = klawSync('/some/dir', {nofile: true})
// dirs = [{path: '/some/dir/dir1', stats: {}}, {path: '/some/dir/dir2', stats: {}}]

ignore hidden directories

const path = require('path')
const klawSync = require('klaw-sync')

const filterFn = item => {
  const basename = path.basename(item.path)
  return basename === '.' || basename[0] !== '.'
}

const paths = klawSync('/some/dir', { filter: filterFn})

filter based on stats

Here traverseAll option is required since we still want to read all subdirectories even if they don't pass the filter function, to see if their contents do pass the filter function.

const klawSync = require('klaw-sync')

const refTime = new Date(2017, 3, 24).getTime()
const filterFn = item => item.stats.mtime.getTime() > refTime

const paths = klawSync('/some/dir', { traverseAll: true, filter: filterFn })

Run tests

lint: npm run lint

unit test: npm run unit

lint & unit: npm test

benchmark: npm run benchmark

Performance compare to other similar modules

Running some benchmark tests on these modules:

(as of Jan 25, 2017) klaw-sync is the fastest module!

results (tested on Ubuntu 18.04, Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz, 8 CPUs, 8g RAM, node v10.9.0)
Running benchmark tests..

root dir length: 1110
walk-sync x 80.71 ops/sec ±1.42% (72 runs sampled)
klaw-sync x 160 ops/sec ±1.17% (79 runs sampled)
Fastest is klaw-sync

root dir length: 11110
walk-sync x 7.55 ops/sec ±3.39% (23 runs sampled)
klaw-sync x 14.95 ops/sec ±0.27% (40 runs sampled)
Fastest is klaw-sync

root dir length: 111110
walk-sync x 0.63 ops/sec ±6.92% (6 runs sampled)
klaw-sync x 1.22 ops/sec ±0.96% (7 runs sampled)
Fastest is klaw-sync

License

Licensed under MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].