77import { compress } from "../../api/text.js"
88import { assertDirectory } from "../../fs/paths.js"
99import { compressFolderToPath } from "../../streaming/folder.js"
10- import { printAnalytics , splitAnalytics } from "../analytics.js"
10+ import { formatBytes , formatCount , printRunSummary , splitAnalytics } from "../analytics.js"
1111import { type Args , readInput , resolveEncoding } from "../args.js"
1212import { writeCompressedOutput } from "../output.js"
1313import { resolveOutputPath } from "../paths.js"
@@ -32,22 +32,23 @@ export async function runCompress(args: Args): Promise<void> {
3232 const elapsedMs = Number ( process . hrtime . bigint ( ) - start ) / 1e6
3333 const ratio = originalBytes === 0 ? 0 : compressedBytes / originalBytes
3434
35- console . log (
36- outputPaths . length === 1
37- ? `Compressed folder written to ${ outputPaths [ 0 ] } `
38- : `Compressed folder written to ${ outputPaths . length } files:\n ${ outputPaths . join ( "\n " ) } ` ,
39- )
40- printAnalytics ( {
41- Encoding : `base${ encoding } ` ,
42- Files : fileCount ,
43- Directories : dirCount ,
44- "Original size (bytes)" : originalBytes ,
45- "Archive size before compression (bytes)" : archiveBytes ,
46- [ `Compressed size (bytes, base${ encoding } )` ] : compressedBytes ,
47- ...splitAnalytics ( splitChunkSize , outputPaths . length ) ,
48- "Size ratio (compressed/original)" : ratio . toFixed ( 3 ) ,
49- "Space saved" : `${ ( ( 1 - ratio ) * 100 ) . toFixed ( 1 ) } %` ,
50- "Time taken (ms)" : elapsedMs . toFixed ( 3 ) ,
35+ printRunSummary ( {
36+ title :
37+ outputPaths . length === 1
38+ ? "Compressed folder"
39+ : `Compressed folder → ${ outputPaths . length } files` ,
40+ outputPaths,
41+ stats : {
42+ Encoding : `base${ encoding } ` ,
43+ Files : formatCount ( fileCount ) ,
44+ Directories : formatCount ( dirCount ) ,
45+ "Original size" : formatBytes ( originalBytes ) ,
46+ "Archive (pre-Brotli)" : formatBytes ( archiveBytes ) ,
47+ [ `Compressed (base${ encoding } )` ] : formatBytes ( compressedBytes ) ,
48+ ...splitAnalytics ( splitChunkSize , outputPaths . length ) ,
49+ "Space saved" : `${ ( ( 1 - ratio ) * 100 ) . toFixed ( 1 ) } %` ,
50+ Time : `${ elapsedMs . toFixed ( 0 ) } ms` ,
51+ } ,
5152 } )
5253 return
5354 }
@@ -68,18 +69,20 @@ export async function runCompress(args: Args): Promise<void> {
6869 const outputBytes = Buffer . byteLength ( result , "utf-8" )
6970 const ratio = inputBytes === 0 ? 0 : outputBytes / inputBytes
7071
71- console . log (
72- outputPaths . length === 1
73- ? `Compressed output written to ${ outputPath } `
74- : `Compressed output written to ${ outputPaths . length } files:\n ${ outputPaths . join ( "\n " ) } ` ,
75- )
76- printAnalytics ( {
77- Encoding : `base${ encoding } ` ,
78- "Original size (bytes)" : inputBytes ,
79- [ `Compressed size (bytes, base${ encoding } )` ] : outputBytes ,
80- ...splitAnalytics ( splitChunkSize , outputPaths . length ) ,
81- "Size ratio (compressed/original)" : ratio . toFixed ( 3 ) ,
82- "Space saved" : `${ ( ( 1 - ratio ) * 100 ) . toFixed ( 1 ) } %` ,
83- "Time taken (ms)" : elapsedMs . toFixed ( 3 ) ,
72+ printRunSummary ( {
73+ title :
74+ outputPaths . length === 1
75+ ? "Compressed text"
76+ : `Compressed text → ${ outputPaths . length } files` ,
77+ outputPaths,
78+ stats : {
79+ Encoding : `base${ encoding } ` ,
80+ "Original size" : formatBytes ( inputBytes ) ,
81+ [ `Compressed (base${ encoding } )` ] : formatBytes ( outputBytes ) ,
82+ ...splitAnalytics ( splitChunkSize , outputPaths . length ) ,
83+ "Size ratio" : ratio . toFixed ( 3 ) ,
84+ "Space saved" : `${ ( ( 1 - ratio ) * 100 ) . toFixed ( 1 ) } %` ,
85+ Time : `${ elapsedMs . toFixed ( 0 ) } ms` ,
86+ } ,
8487 } )
8588}
0 commit comments