9 Commits

Author SHA1 Message Date
30b9c4a1cc bump version 2025-05-29 09:30:10 +10:00
42f770aed9 feat: Add file start and end to read_file function
Signed-off-by: quexeky <git@quexeky.dev>
2025-05-28 22:32:37 +10:00
4670df4127 fix: add windows target 2025-05-28 21:01:16 +10:00
e33eaebe1a fix: refix macos universalisation 2025-05-28 20:52:30 +10:00
f954f23410 fix: longshot fix: add x86_64-unknown-linux-gnu to the list of ABI targets 2025-05-28 20:47:59 +10:00
3632687001 fix: again, macos universalisation 2025-05-28 20:33:56 +10:00
90817487ed fix: universalisation for macos 2025-05-28 20:27:00 +10:00
98b84c64d4 fix: remove problematic builds 2025-05-28 19:58:26 +10:00
d3186cdd5f fix: types 2025-05-28 17:07:12 +10:00
11 changed files with 1601 additions and 388 deletions

View File

@ -46,15 +46,6 @@ jobs:
target: aarch64-unknown-linux-gnu target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: yarn build --target aarch64-unknown-linux-gnu build: yarn build --target aarch64-unknown-linux-gnu
- host: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
setup: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf -y
build: yarn build --target armv7-unknown-linux-gnueabihf
- host: ubuntu-latest
target: armv7-unknown-linux-musleabihf
build: yarn build --target armv7-unknown-linux-musleabihf
- host: ubuntu-latest - host: ubuntu-latest
target: aarch64-unknown-linux-musl target: aarch64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
@ -358,6 +349,8 @@ jobs:
with: with:
name: bindings-aarch64-apple-darwin name: bindings-aarch64-apple-darwin
path: artifacts path: artifacts
- name: Move artifacts
run: mv artifacts/* .
- name: Combine binaries - name: Combine binaries
run: yarn universal run: yarn universal
- name: Upload artifact - name: Upload artifact

View File

@ -22,7 +22,7 @@ time-macros = "0.2.22"
time = "0.3.41" time = "0.3.41"
webpki = "0.22.4" webpki = "0.22.4"
ring = "0.17.14" ring = "0.17.14"
tokio = { version = "1.45.1", features = ["fs"] } tokio = { version = "1.45.1", features = ["fs", "io-util"] }
tokio-util = { version = "0.7.15", features = ["codec"] } tokio-util = { version = "0.7.15", features = ["codec"] }
[dependencies.x509-parser] [dependencies.x509-parser]

33
index.d.ts vendored
View File

@ -1,16 +1,21 @@
/* tslint:disable */
/* eslint-disable */
/* auto-generated by NAPI-RS */ /* auto-generated by NAPI-RS */
/* eslint-disable */
export declare function callAltThreadFunc(tsfn: ((err: Error | null, ) => any)): void
function hasBackendForPath(path: string): boolean export declare function generateClientCertificate(clientId: string, clientName: string, rootCa: string, rootCaPrivate: string): Array<string>
function listFiles(path: string): Array<string>
function readFile(path: string, subPath: string): ReadableStream<Buffer> | null export declare function generateManifest(dir: string, progressSfn: ((err: Error | null, arg: number) => any), logSfn: ((err: Error | null, arg: string) => any), callbackSfn: ((err: Error | null, arg: string) => any)): void
function callAltThreadFunc(tsfn: ((err: Error | null, ) => any)): void
function generateManifest(dir: string, progressSfn: ((err: Error | null, arg: number) => any), logSfn: ((err: Error | null, arg: string) => any), callbackSfn: ((err: Error | null, arg: string) => any)): void export declare function generateRootCa(): Array<string>
function generateRootCa(): Array<string>
function generateClientCertificate(clientId: string, clientName: string, rootCa: string, rootCaPrivate: string): Array<string> export declare function hasBackendForPath(path: string): boolean
function verifyClientCertificate(clientCert: string, rootCa: string): boolean
function signNonce(privateKey: string, nonce: string): string export declare function listFiles(path: string): Array<string>
function verifyNonce(publicCert: string, nonce: string, signature: string): boolean
undefinedundefined export declare function readFile(path: string, subPath: string): ReadableStream<Buffer> | null
export declare function signNonce(privateKey: string, nonce: string): string
export declare function verifyClientCertificate(clientCert: string, rootCa: string): boolean
export declare function verifyNonce(publicCert: string, nonce: string, signature: string): boolean

658
index.js
View File

@ -1,325 +1,387 @@
/* tslint:disable */ // prettier-ignore
/* eslint-disable */ /* eslint-disable */
/* prettier-ignore */ // @ts-nocheck
/* auto-generated by NAPI-RS */ /* auto-generated by NAPI-RS */
const { existsSync, readFileSync } = require('fs') const { createRequire } = require('node:module')
const { join } = require('path') require = createRequire(__filename)
const { platform, arch } = process
const { readFileSync } = require('node:fs')
let nativeBinding = null let nativeBinding = null
let localFileExisted = false const loadErrors = []
let loadError = null
function isMusl() { const isMusl = () => {
// For Node 10 let musl = false
if (!process.report || typeof process.report.getReport !== 'function') { if (process.platform === 'linux') {
try { musl = isMuslFromFilesystem()
const lddPath = require('child_process').execSync('which ldd').toString().trim() if (musl === null) {
return readFileSync(lddPath, 'utf8').includes('musl') musl = isMuslFromReport()
} catch (e) {
return true
} }
} else { if (musl === null) {
const { glibcVersionRuntime } = process.report.getReport().header musl = isMuslFromChildProcess()
return !glibcVersionRuntime }
}
return musl
}
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
const isMuslFromFilesystem = () => {
try {
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
} catch {
return null
} }
} }
switch (platform) { const isMuslFromReport = () => {
case 'android': let report = null
switch (arch) { if (typeof process.report?.getReport === 'function') {
case 'arm64': process.report.excludeNetwork = true
localFileExisted = existsSync(join(__dirname, 'droplet.android-arm64.node')) report = process.report.getReport()
try { }
if (localFileExisted) { if (!report) {
nativeBinding = require('./droplet.android-arm64.node') return null
} else { }
nativeBinding = require('@drop-oss/droplet-android-arm64') if (report.header && report.header.glibcVersionRuntime) {
} return false
} catch (e) { }
loadError = e if (Array.isArray(report.sharedObjects)) {
} if (report.sharedObjects.some(isFileMusl)) {
break return true
case 'arm':
localFileExisted = existsSync(join(__dirname, 'droplet.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./droplet.android-arm-eabi.node')
} else {
nativeBinding = require('@drop-oss/droplet-android-arm-eabi')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Android ${arch}`)
} }
break }
case 'win32': return false
switch (arch) { }
case 'x64':
localFileExisted = existsSync( const isMuslFromChildProcess = () => {
join(__dirname, 'droplet.win32-x64-msvc.node') try {
) return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
try { } catch (e) {
if (localFileExisted) { // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
nativeBinding = require('./droplet.win32-x64-msvc.node') return false
} else { }
nativeBinding = require('@drop-oss/droplet-win32-x64-msvc') }
}
} catch (e) { function requireNative() {
loadError = e if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
}
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, 'droplet.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./droplet.win32-ia32-msvc.node')
} else {
nativeBinding = require('@drop-oss/droplet-win32-ia32-msvc')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'droplet.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./droplet.win32-arm64-msvc.node')
} else {
nativeBinding = require('@drop-oss/droplet-win32-arm64-msvc')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'droplet.darwin-universal.node'))
try { try {
if (localFileExisted) { nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
nativeBinding = require('./droplet.darwin-universal.node') } catch (err) {
} else { loadErrors.push(err)
nativeBinding = require('@drop-oss/droplet-darwin-universal') }
} else if (process.platform === 'android') {
if (process.arch === 'arm64') {
try {
return require('./droplet.android-arm64.node')
} catch (e) {
loadErrors.push(e)
} }
break try {
} catch {} return require('@drop-oss/droplet-android-arm64')
switch (arch) { } catch (e) {
case 'x64': loadErrors.push(e)
localFileExisted = existsSync(join(__dirname, 'droplet.darwin-x64.node')) }
try {
if (localFileExisted) { } else if (process.arch === 'arm') {
nativeBinding = require('./droplet.darwin-x64.node') try {
} else { return require('./droplet.android-arm-eabi.node')
nativeBinding = require('@drop-oss/droplet-darwin-x64') } catch (e) {
} loadErrors.push(e)
} catch (e) { }
loadError = e try {
} return require('@drop-oss/droplet-android-arm-eabi')
break } catch (e) {
case 'arm64': loadErrors.push(e)
localFileExisted = existsSync( }
join(__dirname, 'droplet.darwin-arm64.node')
) } else {
try { loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
if (localFileExisted) {
nativeBinding = require('./droplet.darwin-arm64.node')
} else {
nativeBinding = require('@drop-oss/droplet-darwin-arm64')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`)
} }
break } else if (process.platform === 'win32') {
case 'freebsd': if (process.arch === 'x64') {
if (arch !== 'x64') { try {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`) return require('./droplet.win32-x64-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-win32-x64-msvc')
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'ia32') {
try {
return require('./droplet.win32-ia32-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-win32-ia32-msvc')
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./droplet.win32-arm64-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-win32-arm64-msvc')
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
} }
localFileExisted = existsSync(join(__dirname, 'droplet.freebsd-x64.node')) } else if (process.platform === 'darwin') {
try { try {
if (localFileExisted) { return require('./droplet.darwin-universal.node')
nativeBinding = require('./droplet.freebsd-x64.node') } catch (e) {
} else { loadErrors.push(e)
nativeBinding = require('@drop-oss/droplet-freebsd-x64')
} }
} catch (e) { try {
loadError = e return require('@drop-oss/droplet-darwin-universal')
} catch (e) {
loadErrors.push(e)
}
if (process.arch === 'x64') {
try {
return require('./droplet.darwin-x64.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-darwin-x64')
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./droplet.darwin-arm64.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-darwin-arm64')
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
} }
break } else if (process.platform === 'freebsd') {
case 'linux': if (process.arch === 'x64') {
switch (arch) { try {
case 'x64': return require('./droplet.freebsd-x64.node')
if (isMusl()) { } catch (e) {
localFileExisted = existsSync( loadErrors.push(e)
join(__dirname, 'droplet.linux-x64-musl.node') }
) try {
try { return require('@drop-oss/droplet-freebsd-x64')
if (localFileExisted) { } catch (e) {
nativeBinding = require('./droplet.linux-x64-musl.node') loadErrors.push(e)
} else { }
nativeBinding = require('@drop-oss/droplet-linux-x64-musl')
} } else if (process.arch === 'arm64') {
} catch (e) { try {
loadError = e return require('./droplet.freebsd-arm64.node')
} } catch (e) {
} else { loadErrors.push(e)
localFileExisted = existsSync( }
join(__dirname, 'droplet.linux-x64-gnu.node') try {
) return require('@drop-oss/droplet-freebsd-arm64')
try { } catch (e) {
if (localFileExisted) { loadErrors.push(e)
nativeBinding = require('./droplet.linux-x64-gnu.node') }
} else {
nativeBinding = require('@drop-oss/droplet-linux-x64-gnu') } else {
} loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
} catch (e) { }
loadError = e } else if (process.platform === 'linux') {
} if (process.arch === 'x64') {
} if (isMusl()) {
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'droplet.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./droplet.linux-arm64-musl.node')
} else {
nativeBinding = require('@drop-oss/droplet-linux-arm64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'droplet.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./droplet.linux-arm64-gnu.node')
} else {
nativeBinding = require('@drop-oss/droplet-linux-arm64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'droplet.linux-arm-musleabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./droplet.linux-arm-musleabihf.node')
} else {
nativeBinding = require('@drop-oss/droplet-linux-arm-musleabihf')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'droplet.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./droplet.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('@drop-oss/droplet-linux-arm-gnueabihf')
}
} catch (e) {
loadError = e
}
}
break
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'droplet.linux-riscv64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./droplet.linux-riscv64-musl.node')
} else {
nativeBinding = require('@drop-oss/droplet-linux-riscv64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'droplet.linux-riscv64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./droplet.linux-riscv64-gnu.node')
} else {
nativeBinding = require('@drop-oss/droplet-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, 'droplet.linux-s390x-gnu.node')
)
try { try {
if (localFileExisted) { return require('./droplet.linux-x64-musl.node')
nativeBinding = require('./droplet.linux-s390x-gnu.node') } catch (e) {
} else { loadErrors.push(e)
nativeBinding = require('@drop-oss/droplet-linux-s390x-gnu') }
} try {
} catch (e) { return require('@drop-oss/droplet-linux-x64-musl')
loadError = e } catch (e) {
} loadErrors.push(e)
break }
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`) } else {
try {
return require('./droplet.linux-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-x64-gnu')
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'arm64') {
if (isMusl()) {
try {
return require('./droplet.linux-arm64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-arm64-musl')
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./droplet.linux-arm64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-arm64-gnu')
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'arm') {
if (isMusl()) {
try {
return require('./droplet.linux-arm-musleabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-arm-musleabihf')
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./droplet.linux-arm-gnueabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-arm-gnueabihf')
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'riscv64') {
if (isMusl()) {
try {
return require('./droplet.linux-riscv64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-riscv64-musl')
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./droplet.linux-riscv64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-riscv64-gnu')
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'ppc64') {
try {
return require('./droplet.linux-ppc64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-ppc64-gnu')
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 's390x') {
try {
return require('./droplet.linux-s390x-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@drop-oss/droplet-linux-s390x-gnu')
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
} }
break } else {
default: loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) }
}
nativeBinding = requireNative()
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
try {
nativeBinding = require('./droplet.wasi.cjs')
} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
loadErrors.push(err)
}
}
if (!nativeBinding) {
try {
nativeBinding = require('@drop-oss/droplet-wasm32-wasi')
} catch (err) {
if (process.env.NAPI_RS_FORCE_WASI) {
loadErrors.push(err)
}
}
}
} }
if (!nativeBinding) { if (!nativeBinding) {
if (loadError) { if (loadErrors.length > 0) {
throw loadError // TODO Link to documentation with potential fixes
// - The package owner could build/publish bindings for this arch
// - The user may need to bundle the correct files
// - The user may need to re-install node_modules to get new packages
throw new Error('Failed to load native binding', { cause: loadErrors })
} }
throw new Error(`Failed to load native binding`) throw new Error(`Failed to load native binding`)
} }
const { hasBackendForPath, listFiles, readFile, callAltThreadFunc, generateManifest, generateRootCa, generateClientCertificate, verifyClientCertificate, signNonce, verifyNonce, } = nativeBinding module.exports = nativeBinding
module.exports.callAltThreadFunc = nativeBinding.callAltThreadFunc
module.exports.hasBackendForPath = hasBackendForPath module.exports.generateClientCertificate = nativeBinding.generateClientCertificate
module.exports.listFiles = listFiles module.exports.generateManifest = nativeBinding.generateManifest
module.exports.readFile = readFile module.exports.generateRootCa = nativeBinding.generateRootCa
module.exports.callAltThreadFunc = callAltThreadFunc module.exports.hasBackendForPath = nativeBinding.hasBackendForPath
module.exports.generateManifest = generateManifest module.exports.listFiles = nativeBinding.listFiles
module.exports.generateRootCa = generateRootCa module.exports.readFile = nativeBinding.readFile
module.exports.generateClientCertificate = generateClientCertificate module.exports.signNonce = nativeBinding.signNonce
module.exports.verifyClientCertificate = verifyClientCertificate module.exports.verifyClientCertificate = nativeBinding.verifyClientCertificate
module.exports.signNonce = signNonce module.exports.verifyNonce = nativeBinding.verifyNonce
module.exports.verifyNonce = verifyNonce
module.exports.undefined = undefined

View File

@ -1,3 +0,0 @@
# `@drop-oss/droplet-linux-arm-gnueabihf`
This is the **armv7-unknown-linux-gnueabihf** binary for `@drop-oss/droplet`

View File

@ -1,21 +0,0 @@
{
"name": "@drop-oss/droplet-linux-arm-gnueabihf",
"version": "0.0.0",
"os": [
"linux"
],
"cpu": [
"arm"
],
"main": "droplet.linux-arm-gnueabihf.node",
"files": [
"droplet.linux-arm-gnueabihf.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
},
"repository": {
"url": "https://github.com/Drop-OSS/droplet"
}
}

View File

@ -1,3 +0,0 @@
# `@drop-oss/droplet-linux-arm-musleabihf`
This is the **armv7-unknown-linux-musleabihf** binary for `@drop-oss/droplet`

View File

@ -1,21 +0,0 @@
{
"name": "@drop-oss/droplet-linux-arm-musleabihf",
"version": "0.0.0",
"os": [
"linux"
],
"cpu": [
"arm"
],
"main": "droplet.linux-arm-musleabihf.node",
"files": [
"droplet.linux-arm-musleabihf.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
},
"repository": {
"url": "https://github.com/Drop-OSS/droplet"
}
}

View File

@ -1,6 +1,6 @@
{ {
"name": "@drop-oss/droplet", "name": "@drop-oss/droplet",
"version": "1.2.0", "version": "1.3.0",
"main": "index.js", "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",
"napi": { "napi": {
@ -8,20 +8,21 @@
"triples": { "triples": {
"additional": [ "additional": [
"aarch64-apple-darwin", "aarch64-apple-darwin",
"x86_64-apple-darwin",
"universal-apple-darwin",
"aarch64-unknown-linux-gnu", "aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl", "aarch64-unknown-linux-musl",
"aarch64-pc-windows-msvc", "x86_64-unknown-linux-gnu",
"armv7-unknown-linux-gnueabihf",
"armv7-unknown-linux-musleabihf",
"x86_64-unknown-linux-musl", "x86_64-unknown-linux-musl",
"universal-apple-darwin", "riscv64gc-unknown-linux-gnu",
"riscv64gc-unknown-linux-gnu" "aarch64-pc-windows-msvc",
"x86_64-pc-windows-msvc"
] ]
} }
}, },
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@napi-rs/cli": "2.18.4", "@napi-rs/cli": "3.0.0-alpha.80",
"@types/node": "^22.13.10", "@types/node": "^22.13.10",
"ava": "^6.2.0" "ava": "^6.2.0"
}, },
@ -37,7 +38,7 @@
"build:debug": "napi build --platform", "build:debug": "napi build --platform",
"prepublishOnly": "napi prepublish -t npm", "prepublishOnly": "napi prepublish -t npm",
"test": "ava", "test": "ava",
"universal": "napi universal", "universal": "napi universalize",
"version": "napi version" "version": "napi version"
}, },
"packageManager": "yarn@4.7.0", "packageManager": "yarn@4.7.0",

View File

@ -2,7 +2,7 @@
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use std::{ use std::{
fs::{self, metadata, File}, fs::{self, metadata, File},
io::{self, BufReader, ErrorKind, Read}, io::{self, BufReader, ErrorKind, Read, Seek},
path::{Path, PathBuf}, path::{Path, PathBuf},
task::Poll, task::Poll,
}; };
@ -11,6 +11,7 @@ use napi::{
bindgen_prelude::*, bindgen_prelude::*,
tokio_stream::{Stream, StreamExt}, tokio_stream::{Stream, StreamExt},
}; };
use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeekExt, Take};
use tokio_util::{ use tokio_util::{
bytes::BytesMut, bytes::BytesMut,
codec::{BytesCodec, FramedRead}, codec::{BytesCodec, FramedRead},
@ -134,6 +135,8 @@ pub fn read_file(
path: String, path: String,
sub_path: String, sub_path: String,
env: &Env, env: &Env,
start: Option<u32>,
end: Option<u32>
) -> Option<ReadableStream<'static, BufferSlice<'static>>> { ) -> Option<ReadableStream<'static, BufferSlice<'static>>> {
let path = Path::new(&path); let path = Path::new(&path);
let backend = create_backend_for_path(path).unwrap(); let backend = create_backend_for_path(path).unwrap();
@ -142,14 +145,27 @@ pub fn read_file(
permission: 0, // Shouldn't matter permission: 0, // Shouldn't matter
}; };
// Use `?` operator for cleaner error propagation from `Option` // Use `?` operator for cleaner error propagation from `Option`
let reader = backend.reader(&version_file)?; let mut reader = backend.reader(&version_file)?;
// Can't do this in tokio because it requires a .await, which we can't do here
if let Some(start) = start {
reader.seek(io::SeekFrom::Start(start as u64)).unwrap();
}
// Convert std::fs::File to tokio::fs::File for async operations // Convert std::fs::File to tokio::fs::File for async operations
let reader = tokio::fs::File::from_std(reader); let reader = tokio::fs::File::from_std(reader);
let boxed_reader: Box<dyn AsyncRead + Send + Unpin> = match end {
Some(end_val) => Box::new(reader.take(end_val as u64)),
None => Box::new(reader),
};
// Create a FramedRead stream with BytesCodec for chunking // Create a FramedRead stream with BytesCodec for chunking
let stream = FramedRead::new(reader, BytesCodec::new()) let stream = FramedRead::new(boxed_reader, BytesCodec::new())
// Use StreamExt::map to transform each Result item // Use StreamExt::map to transform each Result item
.map(|result_item| { .map(|result_item| {
result_item result_item

1198
yarn.lock

File diff suppressed because it is too large Load Diff