LoginSignup
2
2

More than 5 years have passed since last update.

emscripten File System APIとUNIXコマンド対応表

Posted at

emscripten File System APIとUNIXコマンド対応表

pwd

FS.cwd

FS.cwd(); // -> "/"

ls

FS.lookupPath

Object.keys(FS.lookupPath("/").node.contents); // -> ["tmp", "home", "dev", "proc"]

ファイルの詳しい情報

var contents = FS.lookupPath("/").node.contents;
Object.keys(contents).map(function(name){
  var o = contents[name];
  var attr = FS.stat(o);
  var mode = attr.mode;
  var size = attr.size;
  var ctime = attr.ctime;
  var uid = attr.uid;
  var gid = attr.gid;
  return [
    FS.isFile(mode),
    FS.isDir(mode),
    FS.isLink(mode),
    FS.isFIFO(mode),
    FS.isChrdev(mode),
    FS.isBlkdev(mode),
    FS.isSocket(mode),
    new Date(ctime).toJSON()
  ];
});

cd

FS.chdir

FS.chdir("/home");

mkdir

FS.mkdir

FS.mkdir("web_user");

rmdir

FS.rmdir

FS.rmdir("web_user");

mv

FS.rename

FS.rename(oldpath, newpath)

rm

FS.unlink

FS.unlink("hoge.txt");

ファイル書き込み

FS.writeFile

バイナリ書き込み

var somedata = new Uint8Array(something);
FS.writeFile("./hoge.png", somedata, {encoding: "binary"});

テキスト書き込み

FS.writeFile("./hoge.txt", "hello world");

追加書き込み

FS.writeFile("./hoge.txt", "hello world!", {flags: "a"});

ファイル読み込み

FS.readFile

バイナリ読み込み

FS.readFile("hoge.png"); // -> Uint8Array

テキスト読み込み

FS.readFile("hoge.txt", {encoding: "utf8"}); // -> "hello wolrd"
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2