-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e69a8e
commit 51496a5
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#! /usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const path = require('path') | ||
const chalk = require('chalk') | ||
const log = console.log | ||
let arr = [] | ||
|
||
fs.readdir(path.resolve(process.cwd()), { withFileTypes: true }, (err, files) => { | ||
if (err) return | ||
|
||
files.forEach((file) => { | ||
if (file.isDirectory()) { | ||
arr.push(chalk.cyan.bold(file.name)) | ||
} else { | ||
arr.push(chalk.white(file.name)) | ||
} | ||
}) | ||
|
||
log(arr.join(' ')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#! /usr/bin/env node | ||
const path = require('path') | ||
const fs = require('fs') | ||
const { createHash } = require('crypto') | ||
|
||
const argv = process.argv | ||
const prefix = `http://cdn.fasionchan.com/course` | ||
const tmp = argv[2] | ||
const host = argv[3] | ||
|
||
function md5 (data) { | ||
return createHash('md5').update(data).digest('hex') | ||
} | ||
|
||
if (!tmp || !host) { | ||
console.log('请输入两个参数') | ||
return | ||
} | ||
|
||
const directory = path.resolve(__dirname, tmp) | ||
|
||
try { | ||
let txt = '' | ||
const files = fs.readdirSync(directory, { | ||
withFileTypes: true | ||
}) | ||
files.forEach((file) => { | ||
let filePath = path.resolve(directory, file.name) | ||
let extname = path.extname(filePath) | ||
let con = fs.readFileSync(filePath) | ||
let md5num = md5(con) | ||
let newFilePath = path.resolve(directory, md5num + extname) | ||
fs.renameSync(filePath, newFilePath) | ||
console.log(`${file.name} ===============> ${md5num}${extname}`) | ||
txt += `![](${prefix}/${host}/${md5num}${extname})\n` | ||
}) | ||
|
||
fs.writeFileSync('pic.md', txt, 'utf8') | ||
|
||
} catch(err) { | ||
console.log('失败了') | ||
console.log(err) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#! /usr/bin/env node | ||
|
||
const net = require('net'); | ||
|
||
const DEFAULT_PORT = 8888; | ||
let argvs = process.argv | ||
argvs.shift(); | ||
argvs.shift(); | ||
console.log(argvs); | ||
|
||
if (argvs[0] === '-l') { | ||
let port = argvs[1] || DEFAULT_PORT; | ||
createNetServer(port); | ||
} | ||
|
||
if (argvs[0] === '-h') { | ||
let host = argvs[1] || 'localhost'; | ||
let port = argvs[3] || DEFAULT_PORT; | ||
createNetClient(host, port); | ||
} | ||
|
||
// process.stdin.on('readable', () => { | ||
// let chunk; | ||
// while((chunk === process.stdin.read()) !== null) { | ||
// process.stdout.write(`数据:${chunk}`) | ||
// } | ||
// }); | ||
|
||
function createNetServer (port) { | ||
let server = net.createServer((client) => { | ||
console.log('client connect'); | ||
|
||
client.on('end', () => { | ||
console.log('client stop connect'); | ||
}) | ||
|
||
client.write('hello from server\r\n'); | ||
client.pipe(client); | ||
}) | ||
|
||
server.on('error', (err) => { | ||
throw err; | ||
}) | ||
|
||
server.listen(port, () => { | ||
console.log('server listen port: ', port); | ||
}) | ||
} | ||
|
||
function createNetClient(host ,port) { | ||
let client = net.createConnection({ | ||
host, | ||
port | ||
}, () => { | ||
console.log('连接服务器'); | ||
client.write('你好\r\n') | ||
}) | ||
|
||
client.on('data', (data) => { | ||
console.log(data.toString()); | ||
}) | ||
|
||
client.on('end', () => { | ||
console.log('已从服务器断开'); | ||
}) | ||
|
||
client.on('error', () => { | ||
console.log('fail'); | ||
}) | ||
} |