Skip to content

Port arraybuffer to ruby #342

Description

@krmbn0576
require "js"

response = JS.global.fetch("<dumped buffer's url>").await
puts response[:status]

arraybuffer = response.arrayBuffer.await

# Expected goal:
#   Marshal.load(arraybuffer)

some byte arrays need to port ruby (typically generated by Marshal.dump), but no fast way

# Correct but too slow way:
uint8array = JS.global[:Uint8Array].new(arraybuffer)
Marshal.load(uint8array.to_a.map(&:to_i).pack("C*")) # Especially the slow JS::Object#to_i on each byte.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions