### Install go-get-folder-size CLI via Go Source: https://github.com/markthree/go-get-folder-size/blob/main/README.md Installs the go-get-folder-size command-line interface using Go's install command. This allows direct execution from the terminal. ```shell go install github.com/markthree/go-get-folder-size ``` -------------------------------- ### Install go-get-folder-size via npm Source: https://github.com/markthree/go-get-folder-size/blob/main/README.md Installs the go-get-folder-size package using npm. This is the first step to using the library in a Node.js project. ```shell npm install go-get-folder-size ``` -------------------------------- ### Run go-get-folder-size CLI Source: https://github.com/markthree/go-get-folder-size/blob/main/README.md Executes the installed go-get-folder-size command-line tool to calculate folder size directly from the terminal. ```shell go-get-folder-size ``` -------------------------------- ### Get Folder Size in Node.js with Loose Option Source: https://github.com/markthree/go-get-folder-size/blob/main/README.md Demonstrates programmatically getting folder sizes in Node.js with the 'loose' option enabled, allowing the process to continue even if some files are inaccessible. Options for pretty printing are also shown. ```typescript 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 ``` -------------------------------- ### CLI for Folder Size Calculation (Bash) Source: https://context7.com/markthree/go-get-folder-size/llms.txt Provides a command-line interface for calculating folder sizes. Supports global installation and npx usage. Options include specifying a base directory, enabling loose mode to ignore errors, and toggling pretty formatting. ```bash # Install globally npm install -g go-get-folder-size # Get size of current directory npx go-get-folder-size # Get size of specific directory npx go-get-folder-size --base ./my-folder npx go-get-folder-size -b /path/to/folder # With loose mode (ignore permission errors) npx go-get-folder-size --loose npx go-get-folder-size -l --base /restricted-folder # Without pretty formatting (raw bytes) npx go-get-folder-size --pretty=false npx go-get-folder-size -p false # Show help npx go-get-folder-size --help npx go-get-folder-size -h # Combine options npx go-get-folder-size -b ./node_modules -l -p ``` -------------------------------- ### Get Folder Size in Node.js (Programmatic) Source: https://github.com/markthree/go-get-folder-size/blob/main/README.md Demonstrates how to programmatically get folder sizes in Node.js using different methods provided by the go-get-folder-size library: binary Go, native Node.js, and WebAssembly Go. The binary Go version is the fastest. ```typescript 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 ``` -------------------------------- ### Get Folder Size in Go (Programmatic) Source: https://github.com/markthree/go-get-folder-size/blob/main/README.md Shows how to use the go-get-folder-size library within a Go program for concurrent and fast folder size calculation. Includes an option to ignore inaccessible files. ```go 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 } ``` -------------------------------- ### IPC Get Folder Size in Node.js Source: https://github.com/markthree/go-get-folder-size/blob/main/README.md Utilizes Inter-Process Communication (IPC) for calculating folder sizes, suitable for multi-path scenarios. Requires manual closing of the IPC connection. ```typescript 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 ``` -------------------------------- ### Platform Detection Utilities (TypeScript) Source: https://context7.com/markthree/go-get-folder-size/llms.txt Provides utility functions to infer the current platform and architecture, detect the appropriate binary name, and determine the default binary path. Includes error handling for unsupported platforms. ```typescript import { inferVersion, detectBinName, detectDefaultBinPath } from "go-get-folder-size"; // Detect platform and architecture const version = inferVersion(); console.log(`Platform version: ${version}`); // Examples: "linux_amd64_v1", "darwin_arm64", "windows_amd64_v1" // Get correct binary name for platform const binName = detectBinName(); console.log(`Binary name: ${binName}`); // Examples: "go-get-folder-size" (Unix), "go-get-folder-size.exe" (Windows) // Get custom version binary name const armBinName = detectBinName("linux_arm64"); console.log(`ARM binary: ${armBinName}`); // "go-get-folder-size" // Get full path to default binary const binPath = detectDefaultBinPath(); console.log(`Binary path: ${binPath}`); // Example: "/node_modules/go-get-folder-size/dist/go-get-folder-size_linux_amd64_v1/go-get-folder-size" // Error handling for unsupported platforms try { const version = inferVersion(); console.log(`Supported platform: ${version}`); } catch (error) { console.error("Unsupported platform or architecture:", error.message); } ``` -------------------------------- ### Run go-get-folder-size CLI with Loose Option Source: https://github.com/markthree/go-get-folder-size/blob/main/README.md Executes the go-get-folder-size CLI, enabling the '--loose' flag to ignore inaccessible files during the folder size calculation. ```shell go-get-folder-size --loose ``` -------------------------------- ### Calculate Folder Size using Native Node.js Source: https://context7.com/markthree/go-get-folder-size/llms.txt A pure Node.js implementation for calculating folder size using recursive directory traversal. It includes special handling for the Bun runtime and supports basic usage, pretty formatting, and graceful handling of permission errors via a 'loose' mode. ```typescript import { getFolderSize } from "go-get-folder-size"; // Basic usage const size = await getFolderSize("./my-project"); console.log(`Project size: ${size} bytes`); // Pretty formatting const readableSize = await getFolderSize("./my-project", true); console.log(`Project size: ${readableSize}`); // "45.2 MB" // Handle permission errors gracefully try { const strictSize = await getFolderSize("/system-folder", false); console.log(`Size: ${strictSize} bytes`); } catch (error) { console.error("Permission denied:", error.message); } // Loose mode - ignore inaccessible files const looseSize = await getFolderSize("/system-folder", false, { loose: true }); console.log(`Accessible size: ${looseSize} bytes`); // Process multiple folders const folders = ["./src", "./dist", "./node_modules"]; const sizes = await Promise.all( folders.map(folder => getFolderSize(folder, false)) ); folders.forEach((folder, i) => { console.log(`${folder}: ${sizes[i]} bytes`); }); ``` -------------------------------- ### Calculate Folder Size using Go Binary (Node.js) Source: https://context7.com/markthree/go-get-folder-size/llms.txt Calculates folder size using a compiled Go binary, providing results in bytes or a human-readable format. Supports specifying a custom binary path and a 'loose' mode to ignore permission errors. ```typescript import { getFolderSizeBin } from "go-get-folder-size"; // Basic usage - returns size in bytes const sizeInBytes = await getFolderSizeBin("./my-folder"); console.log(`Size: ${sizeInBytes} bytes`); // With pretty formatting - returns human-readable string const prettySize = await getFolderSizeBin("./my-folder", true); console.log(`Size: ${prettySize}`); // e.g., "1.5 MB" // With loose mode - ignores permission errors const sizeLoose = await getFolderSizeBin("./my-folder", false, { loose: true }); console.log(`Size: ${sizeLoose} bytes`); // Custom binary path const customSize = await getFolderSizeBin("./my-folder", false, { binPath: "/path/to/custom/binary", loose: false }); console.log(`Size: ${customSize} bytes`); ``` -------------------------------- ### Calculate Folder Size with WebAssembly (TypeScript) Source: https://context7.com/markthree/go-get-folder-size/llms.txt Uses a WebAssembly module to calculate folder sizes, suitable for browser environments. It offers basic usage, pretty formatting, and loose mode for error tolerance. Note that it might be slower than native Node.js implementations. ```typescript import { getFolderSizeWasm } from "go-get-folder-size"; // Basic usage (slowest method, not recommended for production) const size = await getFolderSizeWasm("./folder"); console.log(`Size: ${size} bytes`); // With pretty formatting const prettySize = await getFolderSizeWasm("./folder", true); console.log(`Size: ${prettySize}`); // "3.2 MB" // Loose mode for handling errors const looseSize = await getFolderSizeWasm("./folder", false, { loose: true }); console.log(`Size: ${looseSize} bytes`); // Error handling try { const size = await getFolderSizeWasm("/invalid-path"); console.log(`Size: ${size} bytes`); } catch (error) { console.error("WASM error:", error.message); } ``` -------------------------------- ### Efficient Multi-Folder Size Calculation via IPC (Node.js) Source: https://context7.com/markthree/go-get-folder-size/llms.txt Creates a persistent Go process for efficient calculation of multiple folder sizes. This avoids the overhead of spawning new processes for each request, making it ideal for batch operations. Supports pretty formatting and loose mode. ```typescript import { createGetFolderSizeBinIpc } from "go-get-folder-size"; // Create IPC instance const { getFolderSizeWithIpc, close } = createGetFolderSizeBinIpc(); // Process multiple folders in parallel Promise.all([ getFolderSizeWithIpc("./folder1"), getFolderSizeWithIpc("./folder2"), getFolderSizeWithIpc("./folder3"), getFolderSizeWithIpc("../parent-folder") ]) .then((sizes) => { console.log("Folder sizes:", sizes); // [123456, 789012, 345678, 901234] }) .catch((error) => { console.error("Error:", error.message); }) .finally(close); // Important: manually close the process // With pretty formatting const { getFolderSizeWithIpc: getSize, close: cleanup } = createGetFolderSizeBinIpc(); const prettySize = await getSize("./large-folder", true); console.log(`Size: ${prettySize}`); // "2.5 GB" cleanup(); // With loose mode for permission errors const ipc = createGetFolderSizeBinIpc({ loose: true }); const size = await ipc.getFolderSizeWithIpc("/restricted-folder"); console.log(`Size: ${size} bytes`); ipc.close(); ``` -------------------------------- ### Calculate Folder Size with Go Package (Go) Source: https://context7.com/markthree/go-get-folder-size/llms.txt The core Go function 'Invoke' calculates folder size, supporting concurrent processing and robust error handling. It can process single or multiple directories and the current directory. ```go package main import ( "fmt" "log" getFolderSize "github.com/markthree/go-get-folder-size/src" ) func main() { // Basic usage with error handling size, err := getFolderSize.Invoke("./my-folder") if err != nil { log.Fatalf("Error calculating size: %v", err) } fmt.Printf("Folder size: %d bytes\n", size) // Calculate multiple folders folders := []string{"./src", "./dist", "./tests"} for _, folder := range folders { size, err := getFolderSize.Invoke(folder) if err != nil { fmt.Printf("Error with %s: %v\n", folder, err) continue } fmt.Printf("%s: %d bytes\n", folder, size) } // Current directory size, err = getFolderSize.Invoke(".") if err != nil { log.Fatal(err) } fmt.Printf("Current directory: %d bytes\n", size) } ``` -------------------------------- ### Calculate Folder Size Ignoring Errors with Go (Go) Source: https://context7.com/markthree/go-get-folder-size/llms.txt The 'LooseInvoke' Go function calculates folder size while gracefully ignoring permission errors and inaccessible files, always returning a size value. It's useful for scanning directories where some parts might be restricted. ```go package main import ( "fmt" getFolderSize "github.com/markthree/go-get-folder-size/src" ) func main() { // Loose mode - no error handling needed size := getFolderSize.LooseInvoke("/system-folder") fmt.Printf("Accessible size: %d bytes\n", size) // Calculate multiple folders without worrying about errors folders := []string{"/usr", "/var", "/tmp", "/restricted"} for _, folder := range folders { size := getFolderSize.LooseInvoke(folder) fmt.Printf("%s: %d bytes\n", folder, size) } // Empty or non-existent folders return 0 size = getFolderSize.LooseInvoke("/non-existent") fmt.Printf("Non-existent folder: %d bytes\n", size) // 0 // Compare strict vs loose strictSize, err := getFolderSize.Invoke("/mixed-permissions") looseSize := getFolderSize.LooseInvoke("/mixed-permissions") if err != nil { fmt.Printf("Strict mode failed: %v\n", err) fmt.Printf("Loose mode succeeded: %d bytes\n", looseSize) } else { fmt.Printf("Both modes: %d bytes\n", strictSize) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.