File tree Expand file tree Collapse file tree 2 files changed +12
-14
lines changed
Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @hackmd/api" ,
3- "version" : " 1.0 .0" ,
3+ "version" : " 1.1 .0" ,
44 "description" : " HackMD/CodiMD Node.js API Client" ,
55 "main" : " dist/index.js" ,
66 "declaration" : " ./dist/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ class API {
140140 }
141141 }
142142
143- async export ( noteId : string , type : ExportType , output : string ) {
143+ private async exportRes ( noteId : string , type : ExportType ) {
144144 let res : Response
145145 switch ( type ) {
146146 case ExportType . PDF :
@@ -157,21 +157,19 @@ class API {
157157 res = await this . fetch ( `${ this . serverUrl } /${ noteId } /download` )
158158 }
159159
160- return this . downloadFile ( res , output )
160+ return res
161161 }
162162
163- private async downloadFile ( res : any , output : string ) {
164- const fileStream = fs . createWriteStream ( output )
163+ async exportString ( noteId : string , type : ExportType ) {
164+ const res = await this . exportRes ( noteId , type )
165165
166- await new Promise ( ( resolve , reject ) => {
167- res . body . pipe ( fileStream )
168- res . body . on ( 'error' , ( err : any ) => {
169- reject ( err )
170- } )
171- fileStream . on ( 'finish' , function ( ) {
172- resolve ( )
173- } )
174- } )
166+ return res . text ( )
167+ }
168+
169+ async exportStream ( noteId : string , type : ExportType ) {
170+ const res = await this . exportRes ( noteId , type )
171+
172+ return res . body
175173 }
176174
177175 get fetch ( ) {
You can’t perform that action at this time.
0 commit comments