I'm trying to send the buffer of a zipped dir to an API that expects that, but I'm receiving a kind of weird response:
{
"message": "invalid characters in fileName: store\\\\blocks/\\nError: invalid characters in fileName: store\\\\blocks/\\n at /usr/local/data/service/node_modules/yauzl/index.js:352:83\\n at /usr/local/data/service/node_modules/yauzl/index.js:473:5\\n at /usr/local/data/service/node_modules/fd-slicer/index.js:32:7\\n at FSReqCallback.wrapper [as oncomplete] (fs.js:520:5)"
}
I'm imagining now it's something related to the final file name, but being a buffer I have no idea if it affects or even exists. But if it has, I would love to know how to change it, or if someone has already passed for something like this, how to solve it!
Some code here:
Zip + send
// ? Zip the file, using the zip utils.
let file: Vec<u8> = gzip::file::zip(path);
// ? Send the file to the builder.
match builder::link(file, token) {
Ok(res) => {
println!("{:?}", res.text());
}
Err(e) => {
println!("{:?}", e);
}
}
API
let client = reqwest::blocking::Client::new(); // Create a new HTTP blocking client.
return client // Setup the request.
.post(Routes::assemble(Link)) // Define the endpoint.
.header(ACCEPT, "application/json, text/plain, */*") // Define the headers.
.header(ACCEPT_ENCODING, "gzip") // More headers.
.header(CONTENT_LENGTH, file.len()) // And more headers.
.header(CONTENT_TYPE, "application/octet-stream") // Guess what.
.header(AUTHORIZATION, format!("Bearer {}", token)) // One more.
.body(file) // And finally the body.
.send(); // Just wrap it up and send it.
Resumed zipping function
let mut buf = Vec::new(); // Responsible for handling the buffer and the bytes in it.
let mut cursor = Cursor::new(&mut buf); // Responsible for the cursor.
let mut zip = ZipWriter::new(&mut cursor); // Responsible for the zip writer.
let options = FileOptions::default()
.compression_method(zip::CompressionMethod::Stored)
.unix_permissions(0o755);
let mut buffer = Vec::new();
for entry in it {
let path = entry.path(); // Get the file path
if path.is_file() {
zip.start_file(name.to_str().unwrap(), options).unwrap();
let mut f = File::open(path).unwrap();
f.read_to_end(&mut buffer).unwrap();
zip.write_all(&*buffer).unwrap();
buffer.clear();
} else if name.as_os_str().len() != 0 {
zip.add_directory(name.to_str().unwrap(), options).unwrap();
}
}
zip.finish().unwrap(); // Close the file in the zip archive
drop(zip);
return buf;