File tree Expand file tree Collapse file tree 5 files changed +13
-12
lines changed Expand file tree Collapse file tree 5 files changed +13
-12
lines changed Original file line number Diff line number Diff line change 24
24
## motivation
25
25
26
26
I want to know the folder size quickly, but the nodejs implementation of
27
- [ get-folder-size] ( https://github.com/alessioalex/get-folder-size ) is slow, so using
28
- 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。
27
+ [ get-folder-size] ( https://github.com/alessioalex/get-folder-size ) is slow, so
28
+ using go implements a recursive get folder size that runs in nodejs and is
29
+ ` 7 ~ 20 ` times faster than the node native solution under normal circumstances。
29
30
30
31
<br />
31
32
Original file line number Diff line number Diff line change 19
19
20
20
想要快速知道文件夹大小,但 nodejs 实现的
21
21
[ get-folder-size] ( https://github.com/alessioalex/get-folder-size ) 是慢的,所以用
22
- go 实现了递归获取文件夹大小,能跑在 nodejs 中,正常情况下,比 node 原生方案快 ` 7 ~ 20 ` 倍
22
+ go 实现了递归获取文件夹大小,能跑在 nodejs 中,正常情况下,比 node 原生方案快
23
+ ` 7 ~ 20 ` 倍
23
24
24
25
具体可见 issue 👉
25
26
[ get-folder-size/issues/22] ( https://github.com/alessioalex/get-folder-size/issues/22 )
Original file line number Diff line number Diff line change 6
6
7
7
const { getFolderSizeWithIpc, close } = createGetFolderSizeBinIpc ( ) ;
8
8
9
- const base = "./" ;
9
+ const base = ".. /" ;
10
10
11
11
const nodeStartTime = Date . now ( ) ;
12
12
const nodeResult = await getFolderSize ( base , true ) ;
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export async function getFolderSizeBin(
85
85
} ) ;
86
86
87
87
if ( stderr ) {
88
- throw new Error ( stderr )
88
+ throw new Error ( stderr ) ;
89
89
}
90
90
91
91
if ( pretty ) {
@@ -95,9 +95,7 @@ export async function getFolderSizeBin(
95
95
return Number ( stdout ) ;
96
96
}
97
97
98
- export function createGetFolderSizeBinIpc (
99
- options : Options = { } ,
100
- ) {
98
+ export function createGetFolderSizeBinIpc ( options : Options = { } ) {
101
99
const { binPath = detectDefaultBinPath ( ) , loose = false } = options ;
102
100
103
101
let tasks = new Map <
@@ -128,17 +126,18 @@ export function createGetFolderSizeBinIpc(
128
126
let full = false ;
129
127
function send ( base : string ) {
130
128
if ( full ) {
131
- return go . stdin . once ( "drain" , ( ) => go . stdin . write ( `${ base } ,` ) ) ;
129
+ return go . stdin . once ( "drain" , ( ) => {
130
+ full = false ;
131
+ go . stdin . write ( `${ base } ,` ) ;
132
+ } ) ;
132
133
}
133
134
full = ! go . stdin . write ( `${ base } ,` ) ;
134
135
}
135
136
136
137
readline . on ( "line" , ( item : string ) => {
137
138
const [ base , size ] = item . split ( "," ) ;
138
139
const { pretty, resolve } = tasks . get ( base ) ;
139
- resolve (
140
- pretty ? prettyBytes ( Number ( size ) ) : Number ( size ) ,
141
- ) ;
140
+ resolve ( pretty ? prettyBytes ( Number ( size ) ) : Number ( size ) ) ;
142
141
tasks . delete ( base ) ;
143
142
} ) ;
144
143
You can’t perform that action at this time.
0 commit comments