Skip to content

Commit 56a63b0

Browse files
committed
4.2
1 parent 989c686 commit 56a63b0

File tree

2 files changed

+331
-2
lines changed

2 files changed

+331
-2
lines changed
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
{
2+
"02-the-module-system": {
3+
"01-revealing-module-pattern": {},
4+
"02-module-loader": {},
5+
"03-cjs-circular-dependency": {},
6+
"04-cjs-named-exports": {},
7+
"05-cjs-exporting-a-function": {},
8+
"06-cjs-exporting-a-constructor": {},
9+
"07-cjs-exporting-an-instance": {},
10+
"08-cjs-monkey-patching": {},
11+
"09-esm-syntax": {},
12+
"10-esm-default": {},
13+
"11-esm-async-imports": {},
14+
"12-esm-mixed-exports": {},
15+
"13-esm-read-only-live-bindings": {},
16+
"14-esm-circular-dependency": {},
17+
"15-esm-modifying-other-modules": {},
18+
"16-esm-cjs-interop": {}
19+
},
20+
"03-callbacks-and-events": {
21+
"01-sync-cps": {},
22+
"02-async-cps": {},
23+
"03-non-cps": {},
24+
"04-an-unpredictable-function": {},
25+
"05-fix-zalgo-with-sync-api": {},
26+
"06-deferred-execution": {},
27+
"07-propagating-errors": {},
28+
"08-uncaught-errors": {},
29+
"09-eventemitter-find-regex": {},
30+
"10-eventemitter-extend": {},
31+
"11-eventemitter-sync-emit": {},
32+
"12-events-vs-callbacks": {},
33+
"13-events-plus-callbacks": {
34+
"data": {}
35+
}
36+
},
37+
"04-asynchronous-control-flow-patterns-with-callbacks": {
38+
"01-web-spider": {},
39+
"02-web-spider-functions": {},
40+
"03-sequential-callbacks": {},
41+
"04-web-spider-v2": {},
42+
"05-callback-iteration-pattern": {},
43+
"06-web-spider-v3": {},
44+
"07-callback-unlimited-parallel-execution-pattern": {},
45+
"08-callback-limited-parallel-execution-pattern": {},
46+
"09-queue-limited-parallel-execution-pattern": {},
47+
"10-queue-limited-parallel-execution-with-events": {},
48+
"11-web-spider-v4": {},
49+
"srcFiles": {}
50+
},
51+
"05-asynchronous-control-flow-patterns-with-promises-and-async-await": {
52+
"01-delay-with-promises": {},
53+
"02-promisify": {},
54+
"03-promises-web-spider-v2": {},
55+
"04-promises-web-spider-v3": {},
56+
"05-promises-web-spider-v4": {},
57+
"06-asyncawait-delay": {},
58+
"07-asyncawait-errors": {},
59+
"08-asyncawait-return-await-trap": {},
60+
"09-asyncawait-web-spider-v2": {},
61+
"10-asyncawait-web-spider-v3": {},
62+
"11-asyncawait-web-spider-v4": {},
63+
"12-promises-recursion-leak": {}
64+
},
65+
"06-coding-with-streams": {
66+
"01-gzip-buffer-vs-stream": {},
67+
"02-gzip-server": {
68+
"received_files": {}
69+
},
70+
"03-crypto-gzip-server": {
71+
"received_files": {}
72+
},
73+
"04-readable-non-flowing": {},
74+
"05-readable-flowing": {},
75+
"06-readable-async-iterator": {},
76+
"07-custom-readable": {},
77+
"08-custom-readable-from-iterable": {},
78+
"09-writable-http-entropy-server": {},
79+
"10-writable-http-entropy-server-backpressure": {},
80+
"11-custom-writable-to-file-stream": {},
81+
"12-transform-stream-replace": {},
82+
"13-transform-filter-reduce": {},
83+
"14-passthrough-monitoring": {},
84+
"15-passthrough-late-piping": {
85+
"received_files": {}
86+
},
87+
"15-passthrough-late-piping-alternative": {
88+
"received_files": {}
89+
},
90+
"16-connecting-streams-using-pipes": {},
91+
"17-pipeline-helper": {},
92+
"18-sequential-execution": {},
93+
"19-unordered-parallel-execution": {},
94+
"20-unordered-limited-parallel-execution": {},
95+
"21-ordered-parallel-execution": {},
96+
"22-combined-stream": {},
97+
"23-forking-streams": {},
98+
"24-merging-streams": {},
99+
"25-multiplexing": {}
100+
},
101+
"07-creational-design-patterns": {
102+
"01-factory-simple": {},
103+
"02-factory-dynamic-class": {},
104+
"03-factory-encapsulation": {},
105+
"04-factory-example-profiler": {},
106+
"05-builder-url-builder": {},
107+
"06-revealing-constructor-immutable-buffer": {},
108+
"07-singleton-false-uniqueness": {
109+
"node_modules": {
110+
"package-a": {
111+
"node_modules": {
112+
"mydb": {}
113+
}
114+
},
115+
"package-b": {
116+
"node_modules": {
117+
"mydb": {}
118+
}
119+
}
120+
}
121+
},
122+
"08-singleton-dependencies": {},
123+
"09-dependency-injection": {}
124+
},
125+
"08-structural-design-patterns": {
126+
"01-proxy-composition": {},
127+
"02-proxy-object-literal": {},
128+
"03-proxy-object-augmentation": {},
129+
"04-proxy-es2015": {},
130+
"05-proxy-logging-writable-stream": {},
131+
"06-proxy-reactive": {},
132+
"07-decorator-composition": {},
133+
"08-decorator-object-augmentation": {},
134+
"09-decorator-es2015": {},
135+
"10-decorator-levelup-plugin": {},
136+
"11-adapter": {}
137+
},
138+
"09-behavioral-design-patterns": {
139+
"01-strategy-multiformat-config": {
140+
"samples": {}
141+
},
142+
"02-state-failsafe-socket": {},
143+
"03-template-multiformat-config": {
144+
"samples": {}
145+
},
146+
"04-iterator-alphabet-iterator": {},
147+
"05-iterator-iterable-matrix": {},
148+
"06-iterator-builtins": {},
149+
"07-iterator-fruit-generator": {},
150+
"08-iterator-two-way": {},
151+
"09-iterator-matrix-generator": {},
152+
"10-async-iterator-check-urls": {},
153+
"11-async-generator-check-urls": {},
154+
"12-async-iterator-streams": {},
155+
"13-middleware-zmq": {},
156+
"14-command": {}
157+
},
158+
"10-universal-javascript": {
159+
"01-webpack-intro": {
160+
"src": {}
161+
},
162+
"02-runtime-code-branching": {
163+
"src": {}
164+
},
165+
"03-build-time-code-branching": {
166+
"src": {}
167+
},
168+
"04-module-swapping": {
169+
"src": {}
170+
},
171+
"05-react-hello-world": {
172+
"src": {}
173+
},
174+
"06-react-stateful-component": {
175+
"src": {}
176+
},
177+
"07-frontend-only-app": {
178+
"src": {
179+
"data": {},
180+
"frontend": {
181+
"components": {
182+
"pages": {}
183+
}
184+
}
185+
}
186+
},
187+
"08-server-side-rendering": {
188+
"src": {
189+
"data": {},
190+
"frontend": {
191+
"components": {
192+
"pages": {}
193+
}
194+
}
195+
}
196+
},
197+
"09-asynchronous-data-retrieval": {
198+
"src": {
199+
"data": {},
200+
"frontend": {
201+
"components": {
202+
"pages": {}
203+
}
204+
}
205+
}
206+
},
207+
"10-universal-data-retrieval": {
208+
"src": {
209+
"data": {},
210+
"frontend": {
211+
"components": {
212+
"pages": {}
213+
}
214+
}
215+
}
216+
}
217+
},
218+
"11-advanced-recipes": {
219+
"01-async-init-quick-and-easy": {},
220+
"02-async-init-queues": {},
221+
"03-async-init-queues-state": {},
222+
"04-batching-and-caching": {},
223+
"05-canceling-async-simple": {},
224+
"06-canceling-async-wrapper": {},
225+
"07-canceling-async-generator": {},
226+
"08-cpu-bound": {
227+
"workers": {}
228+
}
229+
},
230+
"12-scalability-and-architectural-patterns": {
231+
"01-plain-http": {},
232+
"02-http-cluster": {},
233+
"03-http-cluster-resilient": {},
234+
"04-http-cluster-zero-downtime": {},
235+
"05-http-load-balancer": {},
236+
"06-http-dynamic-load-balancer": {},
237+
"07-peer-to-peer-load-balancing": {},
238+
"08-scaling-an-app-on-kubernetes": {}
239+
},
240+
"13-messaging-and-integration-patterns": {
241+
"01-pubsub-basic-chat": {
242+
"www": {}
243+
},
244+
"02-pubsub-chat-redis": {
245+
"www": {}
246+
},
247+
"03-pubsub-chat-zmq": {
248+
"www": {}
249+
},
250+
"04-pubsub-amqp": {
251+
"www": {}
252+
},
253+
"05-pubsub-redis-streams": {
254+
"www": {}
255+
},
256+
"06-task-distribution-zmq": {},
257+
"07-task-distribution-amqp": {},
258+
"08-task-distribution-redis-streams": {},
259+
"09-correlation-id": {},
260+
"10-return-address": {}
261+
}
262+
}
Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,78 @@
1-
import { readdir } from 'fs';
1+
import { readdir, writeFile } from 'fs';
22

33
/**
44
* ### 로컬 파일시스템의 디렉터리경로를 입력으로 받으며 비동기적으로 반복하여 발견되는 모든 서브 디렉터리를 비동기적으로 반환.
55
* - 콜백 지옥을 가능하면 피할것.
66
* - 필요하다면 헬퍼함수를 자유롭게 만들어 사용해도 됨.
7+
*
8+
* ### => 나는, 객체로 트리구조 표현해서 콜백에 전달하도록 했다.
79
* @param {string} dir
810
* @param {*} cb
911
* @returns {void}
1012
*/
11-
function listNestedFiles(dir, cb) {}
13+
function listNestedFiles(dir, cb) {
14+
15+
const works = new Set();
16+
17+
const rootDirObj = {};
18+
19+
const next = (nextDir, nextObj, nextCb) => {
20+
works.add(nextDir);
21+
22+
readdir(nextDir, {withFileTypes: true}, (err, files) => {
23+
if (err) {
24+
return cb(err);
25+
};
26+
27+
files
28+
.filter(f => f.isDirectory())
29+
.map(f => f.name)
30+
.filter(f => f.charAt(0) !== '.') // 숨김폴더 제외
31+
.forEach(f => {
32+
nextObj[f] = {};
33+
next(`${nextDir}/${f}`, nextObj[f], (err) => {
34+
if (err) {
35+
return cb(err);
36+
};
37+
});
38+
});
39+
40+
nextCb(null, nextObj);
41+
42+
works.delete(nextDir);
43+
if (works.size === 0) {
44+
cb(null, rootDirObj);
45+
}
46+
});
47+
};
48+
49+
next(dir, rootDirObj, (err, obj) => {
50+
if (err) {
51+
return cb(err);
52+
};
53+
});
54+
55+
}
56+
57+
58+
59+
60+
61+
//--------------------------------------------------------------------------------
62+
63+
64+
65+
listNestedFiles('../', (err, result) => {
66+
if (err) {
67+
console.error(err);
68+
return;
69+
}
70+
71+
writeFile('./listNestedFiles.json', JSON.stringify(result, null, 2), (err) => {
72+
if (err) {
73+
console.error(err);
74+
return;
75+
}
76+
console.log('done');
77+
});
78+
});

0 commit comments

Comments
 (0)