diff --git a/README.md b/README.md
index 0a7e526..08c9b33 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,80 @@
-# nodejsѧϰ¼
+
+
+
+
-[Nodeѧϰ¼¼](https://segmentfault.com/a/1190000009490349)
+# nodejs学习记录
-[Node.jsѧϰ¼: Buffer](https://segmentfault.com/a/1190000009248664)
-[Node.jsѧϰ¼ stream](https://segmentfault.com/a/1190000009254441)
+[Node学习记录:事件](https://segmentfault.com/a/1190000009490349)
-[Node.jsѧϰ¼ 첽I/O](https://segmentfault.com/a/1190000009300468)
+[Node.js学习记录: 理解Buffer](https://segmentfault.com/a/1190000009248664)
-[Nodejsѧϰ¼express](https://segmentfault.com/a/1190000009308075)
+[Node.js学习记录: stream](https://segmentfault.com/a/1190000009254441)
-[Nodejsѧϰ¼첽](https://segmentfault.com/a/1190000009315609)
+[Node.js学习记录: 异步I/O](https://segmentfault.com/a/1190000009300468)
-[Nodeѧϰ¼ дű](https://segmentfault.com/a/1190000009394503)
-[Nodeѧϰ¼ ͼƬ](https://segmentfault.com/a/1190000009406775)
+[Nodejs学习记录:express](https://segmentfault.com/a/1190000009308075)
-[Nodeѧϰ¼](https://segmentfault.com/a/1190000009469920)
+[Nodejs学习记录:异步编程](https://segmentfault.com/a/1190000009315609)
-[Nodejsѧϰ¼: й](https://segmentfault.com/a/1190000009482931)
+[Node学习记录: 写脚本工具](https://segmentfault.com/a/1190000009394503)
+[Node学习记录: 图片爬虫](https://segmentfault.com/a/1190000009406775)
+
+[Node学习记录:网络编程](https://segmentfault.com/a/1190000009469920)
+
+[Nodejs学习记录: 制作命令行工具](https://segmentfault.com/a/1190000009482931)
+
+[Nodejs学习记录: koa2](https://segmentfault.com/a/1190000012858435)
+
+# 学习路径
+
+## 初级开发者
+
+要求:能基于koa/express 开发基本的web服务
+
+学习材料:
+
+
+
+1. 【强烈推荐】博文共赏:Node.js 静态文件服务器实战 https://www.infoq.cn/article/2011/11/tyq-nodejs-static-file-server
+讲述了不依赖任何外部模块实现一个静态文件服务器,初学者看完这个,再去看其它模块的实现方法,基本上就知道了一个web服务的基本原理。
+
+2. 直接看Koa文档和示例,要搞清楚request,response的概念以及相关字段
+
+ - koa官网: https://koajs.com/
+
+- koa examples:https://github.com/koajs/examples
+
+3.能写中间件,知道中间件的含义
+
+ - 学习Koa - 让我们写一个中间件:https://juejin.im/post/5ac9edf1f265da2375072bbb
+- 常用middleware list:https://github.com/koajs/koa/wiki
+- 建议搞清楚几个常见middleware的意义,以及它的源码,以理解更深。eg:https://github.com/nswbmw/koa-ip
+
+
+
+## 中级开发者
+
+要求:能用eggjs,知道eggjs和koa的区别,解决了什么问题,能实现绝大部分复杂的需求,了解常用的模块
+
+1.看完eggjs的文档,知道controler,service的意义
+
+2.知道常用模块的使用。mysql,sequelize,graphql
+
+3.知道和elk融合
+
+
+
+
+
+## 高级开发者
+
+要求:对多进程,代码健壮性,监控告警,性能优化,内存泄露,微服务等有一定的理解
+
+[Node.js 子进程:你应该知道的一切](https://juejin.im/entry/595dc35b51882568d00a97ab?utm_source=gold-miner&utm_medium=readme&utm_campaign=github)
+[解读 Node.js 的 cluster 模块](http://www.alloyteam.com/2015/08/nodejs-cluster-tutorial/)
## License
@@ -26,9 +82,9 @@ MIT
---
-> [jxdxsw.com](http://jxdxsw.com) ·
+> 博客 [jxdxsw.com](http://jxdxsw.com) ·
> GitHub [@AlexZ33](https://github.com/AlexZ33) ·
-> Weibo [@](http://weibo.com/jxtreehouse) ·
+> Weibo [@镜心书社](http://weibo.com/jxtreehouse) ·
> segmentfault [@AlexZ33](https://segmentfault.com/u/alexz33) ·
> Quora [@Alex Zhao](https://www.quora.com/profile/Alex-Zhao-20) ·
-> Źں [@ĵС](http://on891bjlf.bkt.clouddn.com/image/wechat%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E5%8F%B7.jpg)
\ No newline at end of file
+> 微信公众号 [@镜心的小树屋](http://on891bjlf.bkt.clouddn.com/image/wechat%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E5%8F%B7.jpg)
diff --git a/buffer/.gitignore b/buffer/.gitignore
new file mode 100644
index 0000000..ed0d3c8
--- /dev/null
+++ b/buffer/.gitignore
@@ -0,0 +1,88 @@
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+lerna-debug.log*
+
+# Diagnostic reports (https://nodejs.org/api/report.html)
+report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
+
+# Runtime data
+pids
+*.pid
+*.seed
+*.pid.lock
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+*.lcov
+
+# nyc test coverage
+.nyc_output
+
+# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Bower dependency directory (https://bower.io/)
+bower_components
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (https://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directories
+node_modules/
+jspm_packages/
+
+# TypeScript v1 declaration files
+typings/
+
+# TypeScript cache
+*.tsbuildinfo
+
+# Optional npm cache directory
+.npm
+
+# Optional eslint cache
+.eslintcache
+
+# Optional REPL history
+.node_repl_history
+
+# Output of 'npm pack'
+*.tgz
+
+# Yarn Integrity file
+.yarn-integrity
+
+# dotenv environment variables file
+.env
+.env.test
+
+# parcel-bundler cache (https://parceljs.org/)
+.cache
+
+# next.js build output
+.next
+
+# nuxt.js build output
+.nuxt
+
+# vuepress build output
+.vuepress/dist
+
+# Serverless directories
+.serverless/
+
+# FuseBox cache
+.fusebox/
+
+# DynamoDB Local files
+.dynamodb/
diff --git a/buffer/.idea/buffer.iml b/buffer/.idea/buffer.iml
new file mode 100644
index 0000000..24643cc
--- /dev/null
+++ b/buffer/.idea/buffer.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/buffer/.idea/misc.xml b/buffer/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/buffer/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/buffer/.idea/modules.xml b/buffer/.idea/modules.xml
new file mode 100644
index 0000000..a883241
--- /dev/null
+++ b/buffer/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/buffer/.idea/vcs.xml b/buffer/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/buffer/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/buffer/.idea/workspace.xml b/buffer/.idea/workspace.xml
new file mode 100644
index 0000000..0d28526
--- /dev/null
+++ b/buffer/.idea/workspace.xml
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1560252472753
+
+
+ 1560252472753
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/buffer/Buffer.concate.js b/buffer/Buffer.concate.js
new file mode 100644
index 0000000..6712640
--- /dev/null
+++ b/buffer/Buffer.concate.js
@@ -0,0 +1,38 @@
+/**
+ * 正确拼接Buffer
+ *
+ * 正确的拼接方式是用一个数组来储存接收到的所有Buffer片段并记录下所有片段的总长度
+ * 然后调用Buffer.concat()方法生成一个合并的Buffer对象。Buffer.concat()方法封装了从小Buffer对象向大Buffer对象的复制过程,实现十分细腻
+ * @list 要合并的Buffer数组 或 Uint8Array数组
+ * @length 合并后的Buffer的总长度
+ */
+
+Buffer.concat = function (list, length) {
+ if(!Array.isArray(list)) {
+ throw new Error('Usage: Buffer.concat(list, [length])')
+ }
+
+ if(list.length === 0) {
+ return Buffer.alloc(0)
+ } else if (list.length === 1) {
+ return list[0]
+ }
+
+ if(typeof length !== 'number') {
+ length = 0
+ for (let i = 0; i < list.length; i++) {
+ let buf = list[i]
+ length += buf.length
+ }
+ }
+
+ let buffer = Buffer.alloc(length)
+ var pos = 0;
+ for (let i = 0; i < list.length; i++) {
+ let buf = list[i]
+ buf.copy(buffer, pos)
+ pos+=buf.length
+ }
+
+ return buffer
+}
diff --git a/buffer/buffer_concat2.js b/buffer/buffer_concat2.js
new file mode 100644
index 0000000..56fe60e
--- /dev/null
+++ b/buffer/buffer_concat2.js
@@ -0,0 +1,23 @@
+
+const fs = require('fs')
+
+// 从某个文件创建一个字节流
+const stream = fs.createReadStream('test.md', {highWaterMark: 11})
+
+// readable.setEncoding(encoding)
+
+// 默认情况下没有设置字符编码,流数据返回的是 Buffer 对象。 如果设置了字符编码,则流数据返回指定编码的字符串。 例如,调用 readable.setEncoding('utf-8') 会将数据解析为 UTF-8 数据,并返回字符串,调用 readable.setEncoding('hex') 则会将数据编码成十六进制字符串。
+
+// 缺陷: 只能处理UTF-8, Base64, UCS-2/utf-16LE
+// 坑点: https://blog.csdn.net/rcjjian/article/details/81238877
+stream.setEncoding('utf8')
+
+var data = ''
+stream.on('data', function (chunk) {
+ data += chunk
+})
+// console.log('dasddd',stream)
+
+stream.on('end', function () {
+ console.log(data)
+})
\ No newline at end of file
diff --git a/buffer/buffer_concat3.js b/buffer/buffer_concat3.js
new file mode 100644
index 0000000..e69de29
diff --git a/buffer/package.json b/buffer/package.json
new file mode 100644
index 0000000..05ef129
--- /dev/null
+++ b/buffer/package.json
@@ -0,0 +1,5 @@
+{
+ "devDependencies": {
+ "nodemon": "^1.19.1"
+ }
+}
diff --git a/buffer/test.md b/buffer/test.md
new file mode 100644
index 0000000..7b1e870
--- /dev/null
+++ b/buffer/test.md
@@ -0,0 +1 @@
+如果 autoClose 为 false,则即使出现错误,也不会关闭文件描述符。 应用程序负责关闭它并确保没有文件描述符泄漏。 如果 autoClose 设为 true(默认行为),则在 'error' 或 'end' 事件时将自动关闭文件描述符。
\ No newline at end of file
diff --git a/crypto/.vscode/launch.json b/crypto/.vscode/launch.json
new file mode 100644
index 0000000..cfd0d97
--- /dev/null
+++ b/crypto/.vscode/launch.json
@@ -0,0 +1,14 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "node",
+ "request": "launch",
+ "name": "Launch Program",
+ "program": "${workspaceFolder}\\md5.js"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/crypto/dist/h5/index.html b/crypto/dist/h5/index.html
new file mode 100644
index 0000000..52d83cd
--- /dev/null
+++ b/crypto/dist/h5/index.html
@@ -0,0 +1 @@
+h5
\ No newline at end of file
diff --git a/crypto/dist/h5/md5conf.json b/crypto/dist/h5/md5conf.json
new file mode 100644
index 0000000..757302b
--- /dev/null
+++ b/crypto/dist/h5/md5conf.json
@@ -0,0 +1 @@
+{"index.html":"77230e94b5cd88d51a872031531bfecd"}
\ No newline at end of file
diff --git a/crypto/md5.js b/crypto/md5.js
new file mode 100644
index 0000000..33f3948
--- /dev/null
+++ b/crypto/md5.js
@@ -0,0 +1,55 @@
+/**
+ * 导出文件生成md5
+ */
+const fs = require('fs')
+const crypto = require('crypto')
+const rootPath = './dist/h5/'
+const md5File = 'md5conf.json'
+const str = 'h5'
+const re = new RegExp(`\/${str}\/`, 'g')
+
+const files = fs.readdirSync(rootPath)
+
+const md5Info = Object.create(null)
+
+// 替换path
+files.forEach((element, i) => {
+ console.log(element)
+ const filePath = rootPath + element
+ const stat = fs.statSync(filePath)
+ console.log(stat)
+ if(stat.isFile()) { // 如果 fs.Stats 对象描述常规文件,则返回 true
+ const data = fs.readFileSync(filePath, 'utf8');
+ if (/^.*\.(css|js|html)/.test(element)){
+ const newData = data.replace(re, '')
+ console.log("adsdf", newData)
+ fs.writeFileSync(filePath, newData, 'utf8')
+ }
+ }
+});
+
+// 计算md5
+function calcMd5 (path, files) {
+ files.forEach((element, i) => {
+ const filePath = rootPath + element
+ const stat = fs.statSync(filePath)
+ if(stat.isDirectory()) { // 如果 fs.Stats 对象描述文件系统目录,则返回 true。
+ calcMd5(filePath + '/', fs.readdirSync(filePath))
+ } else {
+ const data = fs.readFileSync(filePath)
+ // 计算所有需要被哈希化的数据摘要 (通过 hash.update() 方法)
+ md5Info[filePath.replace(rootPath, '')] = crypto.createHash('md5').update(data).digest('hex')
+ console.log(md5Info)
+ }
+ })
+}
+
+calcMd5(rootPath, files)
+// debugger
+
+// 异步地将数据写入到一个文件,如果文件已存在则覆盖该文件
+let md5InfoStr = JSON.stringify(md5Info)
+fs.writeFile(rootPath + md5File, md5InfoStr, (err) => {
+ if(err) throw err
+ console.log('文件已保存')
+})
diff --git a/crypto/package.json b/crypto/package.json
new file mode 100644
index 0000000..d5a55c2
--- /dev/null
+++ b/crypto/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "crypto-usage",
+ "version": "1.0.0",
+ "description": "",
+ "main": "md5.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "",
+ "license": "ISC"
+}
diff --git a/express/index.js b/express/index.js
new file mode 100644
index 0000000..019e660
--- /dev/null
+++ b/express/index.js
@@ -0,0 +1,16 @@
+const express = require('express')
+const app = express()
+
+app.use(function (req, res, next) {
+ console.log('1')
+ next(new Error('这是一个错误'))
+ console.log('2')
+})
+
+app.use(function (req, res, next) {
+ console.log('3')
+ res.status(200).end()
+ console.log('4')
+})
+
+app.listen(3000)
\ No newline at end of file
diff --git a/fs/resources/a.txt b/fs/resources/a.txt
new file mode 100644
index 0000000..356ce49
--- /dev/null
+++ b/fs/resources/a.txt
@@ -0,0 +1,11 @@
+This is line one
+This is line two
+
+This is line four
+.
+.
+More content here
+.
+.
+
+This is line eleven
diff --git a/fs/resources/badlink b/fs/resources/badlink
new file mode 100644
index 0000000..e3404fe
--- /dev/null
+++ b/fs/resources/badlink
@@ -0,0 +1 @@
+not_existed_file
\ No newline at end of file
diff --git a/fs/resources/cat/file1 b/fs/resources/cat/file1
new file mode 100644
index 0000000..a5bce3f
--- /dev/null
+++ b/fs/resources/cat/file1
@@ -0,0 +1 @@
+test1
diff --git a/fs/resources/cat/file2 b/fs/resources/cat/file2
new file mode 100644
index 0000000..180cf83
--- /dev/null
+++ b/fs/resources/cat/file2
@@ -0,0 +1 @@
+test2
diff --git a/fs/resources/cat/file3 b/fs/resources/cat/file3
new file mode 100644
index 0000000..29f446a
--- /dev/null
+++ b/fs/resources/cat/file3
@@ -0,0 +1 @@
+test3
\ No newline at end of file
diff --git a/fs/resources/cat/file4 b/fs/resources/cat/file4
new file mode 100644
index 0000000..f4538a5
--- /dev/null
+++ b/fs/resources/cat/file4
@@ -0,0 +1,12 @@
+test4-01
+test4-02
+test4-03
+test4-04
+test4-05
+test4-06
+test4-07
+test4-08
+test4-09
+test4-10
+test4-11
+test4-12
diff --git a/fs/resources/cat/file5 b/fs/resources/cat/file5
new file mode 100644
index 0000000..e69de29
diff --git a/fs/resources/chmod/a/b/c/.gitignore b/fs/resources/chmod/a/b/c/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/fs/resources/chmod/b/a/b/.gitignore b/fs/resources/chmod/b/a/b/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/fs/resources/chmod/c/a/b/.gitignore b/fs/resources/chmod/c/a/b/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/fs/resources/chmod/file1 b/fs/resources/chmod/file1
new file mode 100644
index 0000000..db3f9ca
--- /dev/null
+++ b/fs/resources/chmod/file1
@@ -0,0 +1,2 @@
+this is test file 1
+default state should be 0644 (rw-r--r--)
diff --git a/fs/resources/chmod/xdir/deep/file b/fs/resources/chmod/xdir/deep/file
new file mode 100644
index 0000000..02f6335
--- /dev/null
+++ b/fs/resources/chmod/xdir/deep/file
@@ -0,0 +1 @@
+a file
diff --git a/fs/resources/chmod/xdir/file b/fs/resources/chmod/xdir/file
new file mode 100644
index 0000000..02f6335
--- /dev/null
+++ b/fs/resources/chmod/xdir/file
@@ -0,0 +1 @@
+a file
diff --git a/fs/resources/cp-mode-bits/executable b/fs/resources/cp-mode-bits/executable
new file mode 100644
index 0000000..5e40c08
--- /dev/null
+++ b/fs/resources/cp-mode-bits/executable
@@ -0,0 +1 @@
+asdf
\ No newline at end of file
diff --git a/fs/resources/cp/a b/fs/resources/cp/a
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/cp/a
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/cp/b b/fs/resources/cp/b
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/cp/b
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/cp/dir_a/z b/fs/resources/cp/dir_a/z
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/cp/dir_a/z
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/cp/dir_b/dir_b_a/dir_b_a_a/z b/fs/resources/cp/dir_b/dir_b_a/dir_b_a_a/z
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/cp/dir_b/dir_b_a/dir_b_a_a/z
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/cp/fakeLinks/file.txt b/fs/resources/cp/fakeLinks/file.txt
new file mode 100644
index 0000000..0637880
--- /dev/null
+++ b/fs/resources/cp/fakeLinks/file.txt
@@ -0,0 +1 @@
+This is a file
diff --git a/fs/resources/cp/fakeLinks/sym.lnk b/fs/resources/cp/fakeLinks/sym.lnk
new file mode 100644
index 0000000..de8e66c
--- /dev/null
+++ b/fs/resources/cp/fakeLinks/sym.lnk
@@ -0,0 +1 @@
+This is not a link
diff --git a/fs/resources/cp/file1 b/fs/resources/cp/file1
new file mode 100644
index 0000000..180cf83
--- /dev/null
+++ b/fs/resources/cp/file1
@@ -0,0 +1 @@
+test2
diff --git a/fs/resources/cp/links/file.txt b/fs/resources/cp/links/file.txt
new file mode 100644
index 0000000..0637880
--- /dev/null
+++ b/fs/resources/cp/links/file.txt
@@ -0,0 +1 @@
+This is a file
diff --git a/fs/resources/cp/links/sym.lnk b/fs/resources/cp/links/sym.lnk
new file mode 100644
index 0000000..4c33073
--- /dev/null
+++ b/fs/resources/cp/links/sym.lnk
@@ -0,0 +1 @@
+file.txt
\ No newline at end of file
diff --git a/fs/resources/cp/symFolder b/fs/resources/cp/symFolder
new file mode 100644
index 0000000..ce866dd
--- /dev/null
+++ b/fs/resources/cp/symFolder
@@ -0,0 +1 @@
+links/
\ No newline at end of file
diff --git a/fs/resources/exec/slow.js b/fs/resources/exec/slow.js
new file mode 100644
index 0000000..cffff43
--- /dev/null
+++ b/fs/resources/exec/slow.js
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+setTimeout(function() {
+ console.log('slow');
+}, parseInt(process.argv[2], 10));
diff --git a/fs/resources/external/node_script.js b/fs/resources/external/node_script.js
new file mode 100644
index 0000000..3b2d24a
--- /dev/null
+++ b/fs/resources/external/node_script.js
@@ -0,0 +1,2 @@
+console.log('node_script_1234');
+
diff --git a/fs/resources/file1.js b/fs/resources/file1.js
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/fs/resources/file1.js
@@ -0,0 +1 @@
+test
diff --git a/fs/resources/file1.txt b/fs/resources/file1.txt
new file mode 100644
index 0000000..a5bce3f
--- /dev/null
+++ b/fs/resources/file1.txt
@@ -0,0 +1 @@
+test1
diff --git a/fs/resources/file2 b/fs/resources/file2
new file mode 100644
index 0000000..d606037
--- /dev/null
+++ b/fs/resources/file2
@@ -0,0 +1 @@
+test2
\ No newline at end of file
diff --git a/fs/resources/file2.js b/fs/resources/file2.js
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/fs/resources/file2.js
@@ -0,0 +1 @@
+test
diff --git a/fs/resources/file2.txt b/fs/resources/file2.txt
new file mode 100644
index 0000000..180cf83
--- /dev/null
+++ b/fs/resources/file2.txt
@@ -0,0 +1 @@
+test2
diff --git a/fs/resources/find/.hidden b/fs/resources/find/.hidden
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/find/.hidden
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/find/a b/fs/resources/find/a
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/find/a
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/find/b b/fs/resources/find/b
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/find/b
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/find/broken_link b/fs/resources/find/broken_link
new file mode 100644
index 0000000..5b95215
--- /dev/null
+++ b/fs/resources/find/broken_link
@@ -0,0 +1 @@
+non_existent
\ No newline at end of file
diff --git a/fs/resources/find/dir1/a_dir1 b/fs/resources/find/dir1/a_dir1
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/find/dir1/a_dir1
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/find/dir1/dir11/a_dir11 b/fs/resources/find/dir1/dir11/a_dir11
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/find/dir1/dir11/a_dir11
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/find/dir2/a_dir1 b/fs/resources/find/dir2/a_dir1
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/find/dir2/a_dir1
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/grep/case1 b/fs/resources/grep/case1
new file mode 100644
index 0000000..b08f7b0
--- /dev/null
+++ b/fs/resources/grep/case1
@@ -0,0 +1 @@
+Test3
diff --git a/fs/resources/grep/case1.js b/fs/resources/grep/case1.js
new file mode 100644
index 0000000..df6b0d2
--- /dev/null
+++ b/fs/resources/grep/case1.js
@@ -0,0 +1 @@
+test3
diff --git a/fs/resources/grep/case1.txt b/fs/resources/grep/case1.txt
new file mode 100644
index 0000000..bac87cc
--- /dev/null
+++ b/fs/resources/grep/case1.txt
@@ -0,0 +1 @@
+TEST3
diff --git a/fs/resources/grep/file b/fs/resources/grep/file
new file mode 100644
index 0000000..dbb55d2
--- /dev/null
+++ b/fs/resources/grep/file
@@ -0,0 +1,5 @@
+alphaaaaaaabeta
+howareyou
+alphbeta
+this line ends in.js
+lllllllllllllllll.js
diff --git a/fs/resources/grep/file2 b/fs/resources/grep/file2
new file mode 100644
index 0000000..0c37715
--- /dev/null
+++ b/fs/resources/grep/file2
@@ -0,0 +1,3 @@
+-v
+-vv
+-a
diff --git a/fs/resources/head/file1.txt b/fs/resources/head/file1.txt
new file mode 100644
index 0000000..f818b0d
--- /dev/null
+++ b/fs/resources/head/file1.txt
@@ -0,0 +1,50 @@
+file1 1
+file1 2
+file1 3
+file1 4
+file1 5
+file1 6
+file1 7
+file1 8
+file1 9
+file1 10
+file1 11
+file1 12
+file1 13
+file1 14
+file1 15
+file1 16
+file1 17
+file1 18
+file1 19
+file1 20
+file1 21
+file1 22
+file1 23
+file1 24
+file1 25
+file1 26
+file1 27
+file1 28
+file1 29
+file1 30
+file1 31
+file1 32
+file1 33
+file1 34
+file1 35
+file1 36
+file1 37
+file1 38
+file1 39
+file1 40
+file1 41
+file1 42
+file1 43
+file1 44
+file1 45
+file1 46
+file1 47
+file1 48
+file1 49
+file1 50
diff --git a/fs/resources/head/file2.txt b/fs/resources/head/file2.txt
new file mode 100644
index 0000000..37cf79b
--- /dev/null
+++ b/fs/resources/head/file2.txt
@@ -0,0 +1,50 @@
+file2 1
+file2 2
+file2 3
+file2 4
+file2 5
+file2 6
+file2 7
+file2 8
+file2 9
+file2 10
+file2 11
+file2 12
+file2 13
+file2 14
+file2 15
+file2 16
+file2 17
+file2 18
+file2 19
+file2 20
+file2 21
+file2 22
+file2 23
+file2 24
+file2 25
+file2 26
+file2 27
+file2 28
+file2 29
+file2 30
+file2 31
+file2 32
+file2 33
+file2 34
+file2 35
+file2 36
+file2 37
+file2 38
+file2 39
+file2 40
+file2 41
+file2 42
+file2 43
+file2 44
+file2 45
+file2 46
+file2 47
+file2 48
+file2 49
+file2 50
diff --git a/fs/resources/head/shortfile1 b/fs/resources/head/shortfile1
new file mode 100644
index 0000000..180ffe1
--- /dev/null
+++ b/fs/resources/head/shortfile1
@@ -0,0 +1 @@
+short1
diff --git a/fs/resources/head/shortfile2 b/fs/resources/head/shortfile2
new file mode 100644
index 0000000..b0595c7
--- /dev/null
+++ b/fs/resources/head/shortfile2
@@ -0,0 +1 @@
+short2
diff --git a/fs/resources/issue44/main.js b/fs/resources/issue44/main.js
new file mode 100644
index 0000000..d800886
--- /dev/null
+++ b/fs/resources/issue44/main.js
@@ -0,0 +1 @@
+123
\ No newline at end of file
diff --git a/fs/resources/link b/fs/resources/link
new file mode 100644
index 0000000..08219db
--- /dev/null
+++ b/fs/resources/link
@@ -0,0 +1 @@
+file1
\ No newline at end of file
diff --git a/fs/resources/ls/.hidden_dir/nada b/fs/resources/ls/.hidden_dir/nada
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/ls/.hidden_dir/nada
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/ls/.hidden_file b/fs/resources/ls/.hidden_file
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/ls/.hidden_file
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/ls/a_dir/.hidden_dir/nada b/fs/resources/ls/a_dir/.hidden_dir/nada
new file mode 100644
index 0000000..5fedf57
--- /dev/null
+++ b/fs/resources/ls/a_dir/.hidden_dir/nada
@@ -0,0 +1 @@
+nada
\ No newline at end of file
diff --git a/fs/resources/ls/a_dir/b_dir/z b/fs/resources/ls/a_dir/b_dir/z
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/ls/a_dir/b_dir/z
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/ls/a_dir/nada b/fs/resources/ls/a_dir/nada
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/ls/a_dir/nada
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/ls/file1 b/fs/resources/ls/file1
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/fs/resources/ls/file1
@@ -0,0 +1 @@
+test
diff --git a/fs/resources/ls/file1.js b/fs/resources/ls/file1.js
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/fs/resources/ls/file1.js
@@ -0,0 +1 @@
+test
diff --git a/fs/resources/ls/file2 b/fs/resources/ls/file2
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/fs/resources/ls/file2
@@ -0,0 +1 @@
+test
diff --git a/fs/resources/ls/file2.js b/fs/resources/ls/file2.js
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/fs/resources/ls/file2.js
@@ -0,0 +1 @@
+test
diff --git a/fs/resources/ls/filename(with)[chars$]^that.must+be-escaped b/fs/resources/ls/filename(with)[chars$]^that.must+be-escaped
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/ls/filename(with)[chars$]^that.must+be-escaped
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/pushd/a/dummy b/fs/resources/pushd/a/dummy
new file mode 100644
index 0000000..72e12a9
--- /dev/null
+++ b/fs/resources/pushd/a/dummy
@@ -0,0 +1 @@
+meh
\ No newline at end of file
diff --git a/fs/resources/pushd/b/c/dummy b/fs/resources/pushd/b/c/dummy
new file mode 100644
index 0000000..72e12a9
--- /dev/null
+++ b/fs/resources/pushd/b/c/dummy
@@ -0,0 +1 @@
+meh
\ No newline at end of file
diff --git a/fs/resources/rm/a_dir/a_file b/fs/resources/rm/a_dir/a_file
new file mode 100644
index 0000000..8bd6648
--- /dev/null
+++ b/fs/resources/rm/a_dir/a_file
@@ -0,0 +1 @@
+asdf
diff --git a/fs/resources/rm/fake.lnk b/fs/resources/rm/fake.lnk
new file mode 100644
index 0000000..6eab79a
--- /dev/null
+++ b/fs/resources/rm/fake.lnk
@@ -0,0 +1 @@
+missing
\ No newline at end of file
diff --git a/fs/resources/rm/link_to_a_dir b/fs/resources/rm/link_to_a_dir
new file mode 100644
index 0000000..cad027a
--- /dev/null
+++ b/fs/resources/rm/link_to_a_dir
@@ -0,0 +1 @@
+a_dir
\ No newline at end of file
diff --git a/fs/resources/sed/empty.txt b/fs/resources/sed/empty.txt
new file mode 100644
index 0000000..e69de29
diff --git a/fs/resources/shjs/a-file.js b/fs/resources/shjs/a-file.js
new file mode 100644
index 0000000..3050cd9
--- /dev/null
+++ b/fs/resources/shjs/a-file.js
@@ -0,0 +1,2 @@
+console.log('OK!');
+process.exit(0);
diff --git a/fs/resources/shjs/coffeescript.coffee b/fs/resources/shjs/coffeescript.coffee
new file mode 100644
index 0000000..5b27664
--- /dev/null
+++ b/fs/resources/shjs/coffeescript.coffee
@@ -0,0 +1,2 @@
+msg = 'CoffeeScript: OK!'
+console.log msg
diff --git a/fs/resources/shjs/exit-0.js b/fs/resources/shjs/exit-0.js
new file mode 100644
index 0000000..dcbbff6
--- /dev/null
+++ b/fs/resources/shjs/exit-0.js
@@ -0,0 +1 @@
+process.exit(0);
diff --git a/fs/resources/shjs/exit-codes.js b/fs/resources/shjs/exit-codes.js
new file mode 100644
index 0000000..6427ca0
--- /dev/null
+++ b/fs/resources/shjs/exit-codes.js
@@ -0,0 +1 @@
+process.exit(42);
diff --git a/fs/resources/shjs/stdout-stderr.js b/fs/resources/shjs/stdout-stderr.js
new file mode 100644
index 0000000..220cb58
--- /dev/null
+++ b/fs/resources/shjs/stdout-stderr.js
@@ -0,0 +1,2 @@
+console.log('stdout: OK!');
+console.error('stderr: OK!');
diff --git a/fs/resources/sort/file1 b/fs/resources/sort/file1
new file mode 100644
index 0000000..08c3552
--- /dev/null
+++ b/fs/resources/sort/file1
@@ -0,0 +1,12 @@
+22
+symbolic
+46 integers
+melt
+admiral
+aardvark
+scanner
+Dynamite
+Witness
+12345
+blackwater
+5 numbers
diff --git a/fs/resources/sort/file2 b/fs/resources/sort/file2
new file mode 100644
index 0000000..e93f1c2
--- /dev/null
+++ b/fs/resources/sort/file2
@@ -0,0 +1,12 @@
+admiral
+scanner
+5 numbers
+Witness
+46 integers
+12345
+Dynamite
+blackwater
+aardvark
+22
+symbolic
+melt
diff --git a/fs/resources/sort/sorted b/fs/resources/sort/sorted
new file mode 100644
index 0000000..47c1706
--- /dev/null
+++ b/fs/resources/sort/sorted
@@ -0,0 +1,12 @@
+12345
+22
+46 integers
+5 numbers
+aardvark
+admiral
+blackwater
+Dynamite
+melt
+scanner
+symbolic
+Witness
diff --git a/fs/resources/sort/sortedDashN b/fs/resources/sort/sortedDashN
new file mode 100644
index 0000000..9892c34
--- /dev/null
+++ b/fs/resources/sort/sortedDashN
@@ -0,0 +1,12 @@
+aardvark
+admiral
+blackwater
+Dynamite
+melt
+scanner
+symbolic
+Witness
+5 numbers
+22
+46 integers
+12345
diff --git a/fs/resources/uniq/file1 b/fs/resources/uniq/file1
new file mode 100644
index 0000000..8687fd6
--- /dev/null
+++ b/fs/resources/uniq/file1
@@ -0,0 +1,4 @@
+foo
+bar
+bar
+baz
diff --git a/fs/resources/uniq/file1c b/fs/resources/uniq/file1c
new file mode 100644
index 0000000..7162bb4
--- /dev/null
+++ b/fs/resources/uniq/file1c
@@ -0,0 +1,3 @@
+ 1 foo
+ 2 bar
+ 1 baz
diff --git a/fs/resources/uniq/file1d b/fs/resources/uniq/file1d
new file mode 100644
index 0000000..5716ca5
--- /dev/null
+++ b/fs/resources/uniq/file1d
@@ -0,0 +1 @@
+bar
diff --git a/fs/resources/uniq/file1t b/fs/resources/uniq/file1t
new file mode 100644
index 0000000..86e041d
--- /dev/null
+++ b/fs/resources/uniq/file1t
@@ -0,0 +1,3 @@
+foo
+bar
+baz
diff --git a/fs/resources/uniq/file1u b/fs/resources/uniq/file1u
new file mode 100644
index 0000000..86e041d
--- /dev/null
+++ b/fs/resources/uniq/file1u
@@ -0,0 +1,3 @@
+foo
+bar
+baz
diff --git a/fs/resources/uniq/file2 b/fs/resources/uniq/file2
new file mode 100644
index 0000000..2bf57bb
--- /dev/null
+++ b/fs/resources/uniq/file2
@@ -0,0 +1,4 @@
+foo
+bar
+Bar
+baz
diff --git a/fs/resources/uniq/file2u b/fs/resources/uniq/file2u
new file mode 100644
index 0000000..86e041d
--- /dev/null
+++ b/fs/resources/uniq/file2u
@@ -0,0 +1,3 @@
+foo
+bar
+baz
diff --git a/fs/resources/uniq/file3 b/fs/resources/uniq/file3
new file mode 100644
index 0000000..86e041d
--- /dev/null
+++ b/fs/resources/uniq/file3
@@ -0,0 +1,3 @@
+foo
+bar
+baz
diff --git a/fs/resources/uniq/pipe b/fs/resources/uniq/pipe
new file mode 100644
index 0000000..b7eb195
--- /dev/null
+++ b/fs/resources/uniq/pipe
@@ -0,0 +1,50 @@
+bar
+foo
+foo
+baz
+foo
+foo
+bar
+foo
+baz
+baz
+foo
+baz
+baz
+baz
+bar
+baz
+bar
+bar
+baz
+bar
+baz
+foo
+baz
+foo
+baz
+foo
+bar
+baz
+bar
+bar
+bar
+foo
+foo
+foo
+foo
+baz
+foo
+baz
+foo
+foo
+bar
+foo
+foo
+bar
+foo
+foo
+baz
+foo
+foo
+foo
diff --git a/fs/resources/uniq/pipeSorted b/fs/resources/uniq/pipeSorted
new file mode 100644
index 0000000..0e1845d
--- /dev/null
+++ b/fs/resources/uniq/pipeSorted
@@ -0,0 +1,3 @@
+ 12 bar
+ 15 baz
+ 23 foo
diff --git a/fs/resources/which/node b/fs/resources/which/node
new file mode 100644
index 0000000..0b917ba
--- /dev/null
+++ b/fs/resources/which/node
@@ -0,0 +1 @@
+text file, not an executable
diff --git a/fs/utils.js b/fs/utils.js
new file mode 100644
index 0000000..e11d572
--- /dev/null
+++ b/fs/utils.js
@@ -0,0 +1,49 @@
+
+const fs = require('fs')
+
+function statFollowLinks() {
+ return fs.statSync.apply(fs, arguments);
+}
+// test
+//sanity check, if this succeeds, it must be some sort of file
+// let statInfo
+// try {
+// statInfo = statFollowLinks('resources/file1')
+// } catch (e) {
+// throw new Error('no such file or directory: resources/file1')
+// }
+// console.log(statInfo)
+// console.log(statInfo.isFile())
+// console.log(statInfo.isDirectory())
+// console.log(statInfo.mode)
+// console.log(statInfo.mtime.toString())
+exports.statFollowLinks = statFollowLinks;
+
+
+// Normalizes _unlinkSync() across platforms to match Unix behavior, i.e.
+// file can be unlinked even if it's read-only, see https://github.com/joyent/node/issues/3006
+function unlinkSync(file) {
+ try {
+ fs.unlinkSync(file);
+ } catch (e) {
+ // Try to override file permission
+ /* istanbul ignore next */
+ if (e.code === 'EPERM') {
+ fs.chmodSync(file, '0666');
+ fs.unlinkSync(file);
+ } else {
+ throw e;
+ }
+ }
+}
+
+// test
+const paramsFile = 'resources/file1'
+if (fs.existsSync(paramsFile)) unlinkSync(paramsFile);
+
+console.log(paramsFile)
+
+exports.unlinkSync = unlinkSync;
+
+
+
diff --git a/net/README.md b/net/README.md
new file mode 100644
index 0000000..e69de29
diff --git a/net/encoding.js b/net/encoding.js
new file mode 100644
index 0000000..e69de29
diff --git a/net/rpc_data.js b/net/rpc_data.js
new file mode 100644
index 0000000..d6017c8
--- /dev/null
+++ b/net/rpc_data.js
@@ -0,0 +1,26 @@
+const net = require('net');
+const socket = net.connect(12200, '127.0.0.1')
+const HEADER_LEN = 10 // 头部长度
+
+let buf;
+
+socket.on('data', data => {
+ if(!buf) {
+ buf = data
+ } else {
+ buf = Buffer.concat([buf, data])
+ }
+
+ while(buf.length > HEADER_LEN) {
+ console.log(buf.readInt32BE(6))
+ const packetLength = HEADER_LEN + buf.readInt32BE(6)
+ if(buf.length > packetLength) {
+ // 切分出完整的packet
+ const packet = buf.slice(0, packetLength)
+ // 处理 packet逻辑
+ // ...
+
+ buf = buf.slice(packetLength)
+ }
+ }
+})
\ No newline at end of file
diff --git a/net/rpc_readable.js b/net/rpc_readable.js
new file mode 100644
index 0000000..e69de29
diff --git a/net/rpc_stream.js b/net/rpc_stream.js
new file mode 100644
index 0000000..a311923
--- /dev/null
+++ b/net/rpc_stream.js
@@ -0,0 +1 @@
+const net = require('net')
\ No newline at end of file
diff --git a/net/tcp.js b/net/tcp.js
new file mode 100644
index 0000000..e69de29
diff --git a/nodejs-demo-master/package-lock.json b/nodejs-demo-master/package-lock.json
index 82dedff..1c2164b 100644
--- a/nodejs-demo-master/package-lock.json
+++ b/nodejs-demo-master/package-lock.json
@@ -2,6 +2,7 @@
"name": "nba",
"version": "1.0.0",
"lockfileVersion": 1,
+ "requires": true,
"dependencies": {
"bcrypt-nodejs": {
"version": "0.0.3",
@@ -599,9 +600,9 @@
}
},
"moment": {
- "version": "2.16.0",
- "resolved": "https://registry.npmjs.org/moment/-/moment-2.16.0.tgz",
- "integrity": "sha1-848sl8mImw7hj8bMOS4eRDrS2o4="
+ "version": "2.29.2",
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.2.tgz",
+ "integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg=="
},
"mongoose": {
"version": "4.6.5",
diff --git a/rpc/rpc.js b/rpc/rpc.js
new file mode 100644
index 0000000..5550a02
--- /dev/null
+++ b/rpc/rpc.js
@@ -0,0 +1,16 @@
+// 编码
+const payload = {
+ service: 'com.alipay.nodejs.helloService:1.0',
+ methodName: 'plus',
+ args: [1, 2],
+}
+
+const body = new Buffer(JSON.stringify(payload));
+
+const header = new Buffer(10)
+header[0] = 0
+// 开发网络通讯协议的时候操作 Buffer 都应该用大端序的 API,也就是 BE 结尾的。
+header.writeInt32BE(1000, 1)
+
+// Header 里面还需要一个 Byte 标记应用层协议的类型,我们称之为 Codec
+header[5] = 1; // codec => 1代表是json序列化
\ No newline at end of file
diff --git a/stream.js b/stream.js
new file mode 100644
index 0000000..e69de29
diff --git a/worker_threads/worker_threads_demo.js b/worker_threads/worker_threads_demo.js
new file mode 100644
index 0000000..79c3ed4
--- /dev/null
+++ b/worker_threads/worker_threads_demo.js
@@ -0,0 +1,29 @@
+const { isMainThread, parentPort, workerData, threadId, MessageChannel, MessagePort, Worker} = require('worker_threads')
+// 主线程中开启五个子线程
+// 并且主线程向子线程发送简单的消息。
+function mainThread() {
+ for(let i = 0; i < 5; i++) {
+ const worker = new Worker(__filename, { workerData: i})
+ worker.on('exit', code => {
+ console.log(`main: worker stopped with exit code ${code}`)
+ })
+ worker.on('message', msg => {
+ console.log('main: receive ${msg}')
+ worker.postMessage(msg + 1)
+ })
+ }
+}
+
+function workerThread() {
+ console.log(`worker: workerData ${workerData}`)
+ parentPort.on('message', msg => {
+ console.log(`worker: receive ${msg}`)
+ })
+ parentPort.postMessage(workerData)
+}
+
+if(isMainThread) {
+ mainThread()
+} else {
+ workerThread()
+}
\ No newline at end of file