how to readFile before writeToFile()

Open
#2,023 5 comments 0 reactions 1 assignee View on GitHub

@NghiaTranUIT is already working on this.

Since May 14, 2024.

Assessment

This issue has not been assessed yet.

Description

✅ Done question

I understand that ProxyMan provides the functionality to save response.body to a file using the writeToFile() function,
but I seem to have not found a function to read files.

I want to add some conditions before writing to the file, such as whether the file exists and the content of the file,
to determine whether I want to save the file.
In short, I don't want to directly overwrite the existing file.

Here is some pseudocode, as I have not found a relevant implementation method.

async function onResponse(context, url, request, response) {

  const filename = request.queries.page;

  const path = "~/Desktop/" + filename + ".json"
  
  if ("path not exists or content is different from ${response.body}") {
    writeToFile(response.body, path);
  } else {
    // just print some log
  }

  return response;
}
Dominant language
No language data
Stars
7k
Forks
237
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ProxymanApp/Proxyman

All issues in ProxymanApp/Proxyman

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.