2020-08-18 14:55:35 +09:00
|
|
|
const { readFileSync } = require('fs')
|
2020-08-24 17:16:35 +09:00
|
|
|
const { join } = require('path')
|
|
|
|
const { isMainThread, parentPort } = require('worker_threads')
|
|
|
|
|
2020-08-18 14:55:35 +09:00
|
|
|
const bindings = require('../../index.node')
|
|
|
|
|
|
|
|
const filepath = join(__dirname, './example.txt')
|
|
|
|
|
|
|
|
if (!isMainThread) {
|
|
|
|
;(async () => {
|
|
|
|
const fileContent = await bindings.uvReadFile(filepath)
|
|
|
|
const success =
|
|
|
|
Buffer.isBuffer(fileContent) &&
|
|
|
|
readFileSync(filepath).toString('utf8') === fileContent.toString('utf8')
|
|
|
|
parentPort.postMessage(success)
|
2020-08-24 17:16:35 +09:00
|
|
|
})().catch((e) => {
|
|
|
|
throw e
|
|
|
|
})
|
2020-08-18 14:55:35 +09:00
|
|
|
}
|