Skip to content

Commit

Permalink
Add caching utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael B. Gale committed Oct 29, 2024
1 parent 19e7c25 commit 51d90f4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/caching-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/caching-utils.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/caching-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Logger } from "./logging";
import { tryGetFolderBytes } from "./util";

/**
* Returns the total size of all the specified paths.
* @param paths The paths for which to calculate the total size.
* @param logger A logger to record some informational messages to.
* @returns The total size of all specified paths.
*/
export async function getTotalCacheSize(
paths: string[],
logger: Logger,
): Promise<number> {
const sizes = await Promise.all(
paths.map((cacheDir) => tryGetFolderBytes(cacheDir, logger)),
);
return sizes.map((a) => a || 0).reduce((a, b) => a + b, 0);
}

0 comments on commit 51d90f4

Please sign in to comment.