-
Notifications
You must be signed in to change notification settings - Fork 177
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
how to readFile before writeToFile() #2023
Comments
Thanks for your input. I guess I can support a simple version of |
I'm very much looking forward to your new version. I wonder if it will support using JSON parsing to read the contents of files. This way, I can compare file contents more conveniently and specifically. async function onResponse(context, url, request, response) {
const filename = request.queries.page;
const path_to_local_file = "~/Desktop/" + filename + ".json"
if ("path_to_local_file not exists or path_to_local_file content is empty") {
writeToFile(response.body, path_to_local_file);
} else {
var local_file_json = JSON.parse(path_to_local_file's content)
if (local_file_json.some_value != response.body.some_value) {
// to update local file
writeToFile(response.body, path_to_local_file);
} else {
// no nothing or just print some log
}
}
return response;
}
|
@andforce you can try this Beta build: https://download.proxyman.io/beta/Proxyman_5.3.0_New_file_common_func.dmg
async function onResponse(context, url, request, response) {
const textFilePath = "~/Desktop/myfile.json";
// check exist
if (isFileExists(filePath)) {
// read from file
const text = readFromFile(textFilePath);
// pares string to JSON Object
const obj = JSON.parse(text);
}
// Read binary file
const binaryFilePath = "~/Desktop/screenshot.png";
const binaryFile = readFromFile(binaryFilePath); // Uint8Array
// Done
return response;
} |
@NghiaTranUIT Thank you very much; I am amazed by your efficiency. I tried the new beta version you provided, it works fine~ |
Awesome, glad it helps you 👍 |
I understand that ProxyMan provides the functionality to save
response.body
to a file using thewriteToFile()
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.
The text was updated successfully, but these errors were encountered: