提交 1065fa0e 编写于 作者: M Mukaiu 提交者: Huan (李卓桓)

Lazy to create a stream (#470)

上级 3df86361
...@@ -620,7 +620,7 @@ Message.initType() ...@@ -620,7 +620,7 @@ Message.initType()
export class MediaMessage extends Message { export class MediaMessage extends Message {
private bridge: Bridge private bridge: Bridge
private fileStream: NodeJS.ReadableStream private filePath: string
private fileName: string // 'music' private fileName: string // 'music'
private fileExt: string // 'mp3' private fileExt: string // 'mp3'
...@@ -630,7 +630,7 @@ export class MediaMessage extends Message { ...@@ -630,7 +630,7 @@ export class MediaMessage extends Message {
constructor(rawObjOrFilePath: Object | string) { constructor(rawObjOrFilePath: Object | string) {
if (typeof rawObjOrFilePath === 'string') { if (typeof rawObjOrFilePath === 'string') {
super() super()
this.fileStream = fs.createReadStream(rawObjOrFilePath) this.filePath = rawObjOrFilePath
const pathInfo = path.parse(rawObjOrFilePath) const pathInfo = path.parse(rawObjOrFilePath)
this.fileName = pathInfo.name this.fileName = pathInfo.name
...@@ -785,8 +785,8 @@ export class MediaMessage extends Message { ...@@ -785,8 +785,8 @@ export class MediaMessage extends Message {
// } // }
public async readyStream(): Promise<NodeJS.ReadableStream> { public async readyStream(): Promise<NodeJS.ReadableStream> {
if (this.fileStream) if (this.filePath)
return this.fileStream return fs.createReadStream(this.filePath)
try { try {
await this.ready() await this.ready()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册