Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DataStore .writeRaw and readRaw methods #332

Closed
3 tasks done
tomasciccola opened this issue Oct 9, 2023 · 0 comments · Fixed by #334
Closed
3 tasks done

add DataStore .writeRaw and readRaw methods #332

tomasciccola opened this issue Oct 9, 2023 · 0 comments · Fixed by #334
Assignees

Comments

@tomasciccola
Copy link
Contributor

tomasciccola commented Oct 9, 2023

Description

In order to write and read an arbritrary Buffer to the DataStore we need a writeRaw and readRaw methods

Tasks

  • Create writeRaw implementation
  • Create readRaw implementation
  • Write unit tests

rough implementation

  /** @param {string} versionId */
  async readRaw(versionId) {
    const { coreDiscoveryKey, index } = parseVersionId(versionId)
    const core = this.#coreManager.getCoreByDiscoveryKey(coreDiscoveryKey)
    if (!core) throw new Error('Invalid versionId')
    const block = await core.get(index, { wait: false })
    if (!block) throw new Error('Not Found')
    return block
  }

 async writeRaw(buf) {
    const { length } = await this.#writerCore.append(buf)
    const index = length - 1
    const coreDiscoveryKey = this.#writerCore.discoveryKey
    if (!coreDiscoveryKey) {
      throw new Error('Writer core is not ready')
    }
    const versionId = getVersionId({ coreDiscoveryKey, index })
    return versionId
  }
@tomasciccola tomasciccola self-assigned this Oct 9, 2023
This was referenced Oct 9, 2023
@tomasciccola tomasciccola changed the title add DataStore.writeRaw method add DataStore .writeRaw and readRaw methods Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant