2020-08-24 17:16:35 +09:00
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
import test from 'ava'
|
|
|
|
|
|
|
|
import { napiVersion } from '../napi-version'
|
2020-07-03 01:31:50 +09:00
|
|
|
|
|
|
|
const bindings = require('../../index.node')
|
2020-06-19 21:42:18 +09:00
|
|
|
|
|
|
|
const filepath = path.resolve(__dirname, './example.txt')
|
|
|
|
|
|
|
|
test('should read a file and return its a buffer', async (t) => {
|
2020-07-03 01:31:50 +09:00
|
|
|
if (napiVersion < 4) {
|
|
|
|
t.is(bindings.testTokioReadfile, undefined)
|
|
|
|
return
|
|
|
|
}
|
2020-08-24 19:01:55 +09:00
|
|
|
await new Promise((resolve, reject) => {
|
2020-08-24 17:16:35 +09:00
|
|
|
bindings.testTokioReadfile(filepath, (err: Error | null, value: Buffer) => {
|
2020-06-19 21:42:18 +09:00
|
|
|
try {
|
|
|
|
t.is(err, null)
|
|
|
|
t.is(Buffer.isBuffer(value), true)
|
|
|
|
t.is(value.toString(), fs.readFileSync(filepath, 'utf8'))
|
|
|
|
resolve()
|
|
|
|
} catch (err) {
|
|
|
|
reject(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|