Comments (3)
Thanks for your suggestion!
I think adding a utility function (as a context manager) similar to your decrypt_office_file()
to the library is a good idea and will do it.
In the case of your code example, I might replace decrypted_file = file
with decrypted_file = BytesIO(f)
so that the function always returns BytesIO.
I also find it really odd that
.decrypt()
takes the object you want to inject the file into as an argument, rather than returning a BytesIO object? It makes following the code flow feel awkward to me, but that's a for another day!
I understand. The problem is that always creating a BytesIO object can consume unnecessary memory, especially if the document is large in file size.
from msoffcrypto-tool.
Thanks for your suggestion! I think adding a utility function (as a context manager) similar to your
decrypt_office_file()
to the library is a good idea and will do it. In the case of your code example, I might replacedecrypted_file = file
withdecrypted_file = BytesIO(f)
so that the function always returns BytesIO.Brilliant, I just threw that together to get what I needed, I'm sure you'll make it better 😄
I understand. The problem is that always creating a BytesIO object can consume unnecessary memory, especially if the document is large in file size.
~ snip ~ I wrote a load of nonsense, I'm sure you know what you're doing! Plus, this way can support alternatives to just BytesIO which is nice, I guess you could
with open as f
and passf
asofile
!
There will probably be a lot of people like me who forgot to f.seek(0)
😂.
with open(file_path, 'rb') as f:
file = msoffcrypto.OfficeFile(f)
if file.is_encrypted():
file.load_key(password=password) # Use password
file.decrypt(decrypted_io)
else:
f.seek(0) # don't forget this
decrypted_io.write(f.read())
return decrypted_io
from msoffcrypto-tool.
Thanks for your suggestion! I think adding a utility function (as a context manager) similar to your
decrypt_office_file()
to the library is a good idea and will do it. In the case of your code example, I might replacedecrypted_file = file
withdecrypted_file = BytesIO(f)
so that the function always returns BytesIO.
Brilliant, I just threw that together to get what I needed, I'm sure you'll make it better 😄
I understand. The problem is that always creating a BytesIO object can consume unnecessary memory, especially if the document is large in file size.
~ snip ~ I wrote a load of nonsense, I'm sure you know what you're doing! Plus, this way can support alternatives to just BytesIO which is nice, I guess you could with open as f
and pass f
as ofile
!
from msoffcrypto-tool.
Related Issues (20)
- Standalone binaries/executables HOT 3
- UnboundLocalError: local variable 'obuf' referenced before assignment HOT 2
- if I input an .xls file, decrypted file is .xlsx format? HOT 1
- Module doesnt work when compiled into a binary HOT 2
- Problem using msoffcrypto after unzipping a file in python HOT 2
- How can I tell if my password is misspelled? HOT 1
- Decrypt XLS File HOT 7
- xls97.decrypt - Missing type attribute HOT 3
- Invalid Key - Payload Error
- TypeError: Xls97File.load_key() got an unexpected keyword argument 'verify_password' HOT 1
- Unprotected file raising FileFormatError instead of returning False when checked with is_encrypted() HOT 1
- Issue with package distribution metadata set for package version. HOT 1
- Encrypted File raises FileFormatError: Unrecognized file format, using Sensitivity Label HOT 1
- Is there any plan to support decryption of XORObfuscation algorithm? HOT 6
- Weird issue when using emca376_agile as an import HOT 2
- Thank you HOT 1
- struct.error: unpack requires a buffer of 4 bytes HOT 2
- how to decrypt ppt Pictures stream ?
- Suggestion: Have implementation of BaseOfficeFile's functions support any parameters
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msoffcrypto-tool.