Skip to content

Commit 0add389

Browse files
committed
Remove file writing from api client
1 parent 5076f2a commit 0add389

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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",

nodejs/src/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff 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() {

0 commit comments

Comments
 (0)