(file: string)
| 29 | const hackMdCache = new Map<string, Promise<string[]>>(); |
| 30 | |
| 31 | export async function readLines(file: string): Promise<string[]> { |
| 32 | file = file.replace('https:/', 'https://').replace('https:///', 'https://'); |
| 33 | let promise = hackMdCache.get(file); |
| 34 | if (promise) return promise; |
| 35 | |
| 36 | const index = file.indexOf('https://hackmd.io/'); |
| 37 | if (index === -1) { |
| 38 | promise = new Promise((res, rej) => |
| 39 | readFile(file, (err, data) => (err ? rej(err) : res(String(data).split('\n')))) |
| 40 | ); |
| 41 | } else { |
| 42 | const url = file.substring(index) + '/download'; |
| 43 | console.log('FETCHING:', url); |
| 44 | promise = new Promise<string[]>((resolve, rej) => { |
| 45 | get(url, (res) => { |
| 46 | res.setEncoding('utf8'); |
| 47 | let body = ''; |
| 48 | res.on('data', (data) => { |
| 49 | body += String(data); |
| 50 | }); |
| 51 | res.on('end', () => { |
| 52 | resolve(body.split('\n')); |
| 53 | }); |
| 54 | }); |
| 55 | }); |
| 56 | } |
| 57 | hackMdCache.set(file, promise); |
| 58 | return promise; |
| 59 | } |
| 60 | |
| 61 | export async function writeFileLines(file: string, lines: string[]) { |
| 62 | return new Promise((res, rej) => |
no test coverage detected
searching dependent graphs…