How to use the web-ext-native-msg.readFile function in web-ext-native-msg

To help you get started, we’ve selected a few web-ext-native-msg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asamuzaK / withExEditorHost / modules / main.js View on Github external
const getTmpFileFromFileData = async (fileData = {}) => {
  const {dataId, dir, host, tabId, windowId} = fileData;
  const func = [];
  let msg;
  if (dataId && dir && host && tabId && windowId && fileMap[dir]) {
    const fileId = [windowId, tabId, host, dataId].join("_");
    if (fileMap[dir].has(fileId)) {
      const {filePath} = fileMap[dir].get(fileId);
      if (isFile(filePath)) {
        const value = await readFile(filePath, {encoding: CHAR, flag: "r"});
        const timestamp = await getFileTimestamp(filePath);
        const data = fileData;
        data.timestamp = timestamp;
        msg = {
          [TMP_FILE_RES]: {data, value},
        };
        func.push(writeStdout(msg));
      } else {
        fileMap[dir].delete(fileId);
      }
    }
  }
  if (!msg) {
    const data = fileData;
    data.timestamp = FILE_NOT_FOUND_TIMESTAMP;
    msg = {
github asamuzaK / withExEditorHost / modules / main.js View on Github external
const getEditorConfig = async editorConfigPath => {
  const func = [];
  if (isFile(editorConfigPath)) {
    const data = await readFile(editorConfigPath, {
      encoding: CHAR, flag: "r",
    });
    func.push(exportEditorConfig(data, editorConfigPath));
  } else {
    func.push(
      writeStdout(hostMsg(`No such file: ${editorConfigPath}`, "warn")),
      writeStdout({[EDITOR_CONFIG_RES]: null}),
    );
  }
  return Promise.all(func);
};
github asamuzaK / withExEditorHost / modules / main.js View on Github external
const createTmpFileResMsg = async key => {
  let func;
  if (isString(key) && isFile(key)) {
    const fileId = await getFileIdFromFilePath(key);
    if (fileId) {
      const obj = fileMap[TMP_FILES].get(fileId);
      if (obj) {
        const {data} = obj;
        if (data) {
          const value =
            await readFile(key, {encoding: CHAR, flag: "r"}) || "";
          data.timestamp = await getFileTimestamp(key);
          func = writeStdout({
            [TMP_FILE_RES]: {
              data, value,
            },
          });
        }
      }
    }
  }
  return func || null;
};