提交 be843217 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

demo how to save contact avatar to file #121 #138

上级 49032810
......@@ -7,6 +7,8 @@
*
*/
import { createWriteStream } from 'fs'
/* tslint:disable:variable-name */
const QrcodeTerminal = require('qrcode-terminal')
......@@ -85,7 +87,15 @@ async function main() {
await contact.refresh()
}
log.info('Bot', 'Contact: %s: %s', contact.weixin(), contact.name())
/**
* Save avatar to file like: "1-name.jpg"
*/
const avatarFileName = `${i}-${contact.name()}.jpg`
const avatarReadStream = await contact.avatar()
const avatarWriteStream = createWriteStream(avatarFileName)
avatarReadStream.pipe(avatarWriteStream)
log.info('Bot', 'Contact: %s: %s with avatar file: %s', contact.weixin(), contact.name(), avatarFileName)
if (i > MAX) {
log.info('Bot', 'Contacts too many, I only show you the first %d ... ', MAX)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册