Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

10/27/2019

Python: Create in Memory Zip File

simple example to make zip in memory

..
import io
import zipfile

def makeZip(data_list):
    zip_buffer = io.BytesIO()
    with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED, Falseas zip_file:
        for file_name, data in data_list:
            zip_file.writestr(file_name, data.getvalue())
    return zip_buffer

data_list = [('1.txt', io.BytesIO(b'111')), ('2.txt', io.BytesIO(b'222'))]
zip_buffer = makeZip(data_list)
with open('./b.zip''wb'as f:
    f.write(zip_buffer.getvalue())
..

Thank you.

7/20/2018

get file list in the folder (example code)

example code


namespace fs = std::experimental::filesystem;

std::vector<std::string> list_files_in_dir(string dirPath)
{
 vector<string> r;
 
 for (auto & p : fs::directory_iterator(dirPath))
 {
  std::cout << p.path().string() << std::endl;
  r.push_back(p.path().string());
 }
 
 return r;
}