Skip to content

Instantly share code, notes, and snippets.

@joncardasis
Created November 4, 2025 23:00
Show Gist options
  • Select an option

  • Save joncardasis/f030cac441fb2680a6676bda00f3c873 to your computer and use it in GitHub Desktop.

Select an option

Save joncardasis/f030cac441fb2680a6676bda00f3c873 to your computer and use it in GitHub Desktop.
Parse and print contents of a rive file
import fs from 'fs'
import Rive, {
Alignment,
Fit,
Layout,
Rive,
RiveFile,
FileAsset,
useStateMachineInput,
} from '@rive-app/react-webgl2'
async function main() {
const fileBuffer = fs.readFileSync(
'/Users/jon/Workspace/rives/demo.riv'
)
console.log('File buffer length:', fileBuffer.length)
let arrayBuffer = fileBuffer.buffer.slice(
fileBuffer.byteOffset,
fileBuffer.byteOffset + fileBuffer.byteLength
)
arrayBuffer =
arrayBuffer instanceof SharedArrayBuffer ? arrayBuffer.slice() : arrayBuffer
const riveFile = new RiveFile({buffer: arrayBuffer})
await riveFile.init()
// const file = (await rive.load(new Uint8Array(arrayBuffer))) as File
console.log({riveFile, arrayBuffer})
const file = riveFile.getInstance()
for (let i = 0; i < file.artboardCount(); i++) {
const artboard = file.artboardByIndex(i)
console.log('Artboard Name:', artboard.name)
for (let j = 0; j < artboard.stateMachineCount(); j++) {
const stateMachine = artboard.stateMachineByIndex(j)
console.log(' State Machine Name:', stateMachine.name)
}
for (let j = 0; j < artboard.animationCount(); j++) {
const animation = artboard.animationByIndex(j)
console.log(' Animation Name:', animation.name)
}
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment