Skip to content

I can't open a file in /data #240

Answered by silver-zepp
mimimix asked this question in Q&A
Discussion options

You must be logged in to vote

I see now. Here's a working example for you to play with:

import { openAssetsSync, readSync, } from "@zos/fs";

const FILE_PATH = "data/test.txt";

function bufferToString(buffer){
  return String.fromCharCode.apply(null, new Uint8Array(buffer));
}

Page({
  build() {
    const fd = openAssetsSync({
      path: FILE_PATH,
      flag: O_RDONLY,
    });

    const buffer = new ArrayBuffer(1024);
    const result = readSync({
      fd,
      buffer,
    });

    if (result > 0) {
      console.log("readSync succeed");
      console.log(bufferToString(buffer));
    } else {
      console.log("readSync failed", result);
    }
  },
});

Your hierarchy for this project should be: assets/390x450-g…

Replies: 5 comments 14 replies

Comment options

You must be logged in to vote
1 reply
@mimimix
Comment options

Comment options

You must be logged in to vote
8 replies
@silver-zepp
Comment options

@mimimix
Comment options

@silver-zepp
Comment options

@mimimix
Comment options

@silver-zepp
Comment options

Answer selected by mimimix
Comment options

You must be logged in to vote
1 reply
@silver-zepp
Comment options

Comment options

You must be logged in to vote
3 replies
@silver-zepp
Comment options

@silver-zepp
Comment options

@SashaCX75
Comment options

Comment options

You must be logged in to vote
1 reply
@oakeley
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants