Skip to content

go concurrently get folder size quickly, can run in nodejs | go 并发快速获取文件夹大小,可以跑在 nodejs 中

License

Notifications You must be signed in to change notification settings

markthree/go-get-folder-size

Repository files navigation

go concurrently get folder size quickly, can run in nodejs


README 🦉

简体中文 | English


features


motivation

I want to know the folder size quickly, but the nodejs implementation of get-folder-size is slow, so using go implements a recursive get folder size that runs in nodejs and is 7 ~ 20 times faster than the node native solution under normal circumstances。


Usage

npm

install

npm install go-get-folder-size

cli

# Binary go, fastest
npx go-get-folder-size

program

import {
  getFolderSize,
  getFolderSizeBin,
  getFolderSizeWasm,
} from "go-get-folder-size";

const base = "./"; // The directory path you want to get

await getFolderSizeBin(base); // Binary go, fastest

await getFolderSize(base); // native node

await getFolderSizeWasm(base); // Wasm go,slowest
IPC

Suitable for multi-path

import { createGetFolderSizeBinIpc } from "go-get-folder-size";

const { getFolderSizeWithIpc, close } = createGetFolderSizeBinIpc();

Promise.all([
  getFolderSizeWithIpc("./"),
  getFolderSizeWithIpc("../"),
])
  .then((vs) => console.log(vs))
  .finally(close); // Manual close is required

go

cli

go install github.com/markthree/go-get-folder-size
go-get-folder-size

program

# Super invincible fast
go get github.com/markthree/go-get-folder-size
package main

import (
	getFolderSize "github.com/markthree/go-get-folder-size/src"
)

func main() {
	size, err := getFolderSize.Invoke("./") // Concurrent running, invincible fast

  size2 := getFolderSize.LooseInvoke("./") // Sometimes we may encounter inaccessible files, and we can set 'loose' to ignore them
}

loose

Sometimes we may encounter inaccessible files, and we can set loose to ignore them

cli

go-get-folder-size --loose

program

import {
  getFolderSize,
  getFolderSizeBin,
  getFolderSizeWasm,
} from "go-get-folder-size";

const base = "./"; // The directory path you want to get
const pretty = false; // Human readable way
const loose = true;

await getFolderSizeBin(base, pretty, { loose }); // Binary go, fastest

await getFolderSize(base, pretty, { loose }); // native node

await getFolderSizeWasm(base, pretty, { loose }); // Wasm go,slowest

stack


License

Made with markthree

Published under MIT License.