Smart_open: Multiple files inside target zip file

Created on 30 Apr 2019  路  3Comments  路  Source: RaRe-Technologies/smart_open

It would be nice having the ability to write multiple zip-entries (meaning, multiple source files) to the target zip file. Something like this:

```python
s3_objects = client.list_objects(Bucket=bucket, Delimiter='/', Prefix=key)
with open('s3://my_bucket/my-file.zip', 'w') as fout:
for s3_object in s3_objects.get('Contents'):
s3_object = s3.Object(bucket, s3_object.get('Key'))
fout.write(s3_object.get('Key'), s3_object.get()['Body'].read().decode('utf-8'))
````
Is this something to be considered?

Most helpful comment

Archives are not supported by smart_open -- see previous discussion in #134 and #205, and especially this comment for a better solution: https://github.com/RaRe-Technologies/smart_open/pull/205#issuecomment-419821951

All 3 comments

Archives are not supported by smart_open -- see previous discussion in #134 and #205, and especially this comment for a better solution: https://github.com/RaRe-Technologies/smart_open/pull/205#issuecomment-419821951

I've thought about it, but I think it's out of scope for this library. You could probably achieve what you want by using smart_open in combinaton with the zipfile module of the standard library:

import zipfile
with open('s3://my_bucket/my-file.zip', 'w') as fout:
    with zipfile.ZipFile(fout) as foutz:
        for data in data_list:
            ...

Thanks for the directions @piskvorky and @mpenkov

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jayantj picture jayantj  路  3Comments

eschwartz picture eschwartz  路  5Comments

ivan-yankovyi picture ivan-yankovyi  路  4Comments

dmcguire81 picture dmcguire81  路  5Comments

MartinThoma picture MartinThoma  路  3Comments