https://github.com/jpf/filegenerator
A file-like object class for Python. Reads go into a Queue, writes come from the queue via a generator.
https://github.com/jpf/filegenerator
Last synced: 19 days ago
JSON representation
A file-like object class for Python. Reads go into a Queue, writes come from the queue via a generator.
- Host: GitHub
- URL: https://github.com/jpf/filegenerator
- Owner: jpf
- License: mit
- Created: 2013-07-23T20:46:07.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-07-28T06:41:01.000Z (almost 13 years ago)
- Last Synced: 2026-05-13T10:48:30.206Z (21 days ago)
- Language: Python
- Size: 105 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is a sorta-StringIO-like file-like object where writes go into a Queue and reads are done via a generator.
I wrote this to allow myself to stream a file as the file was being written.
I'm not sure if this code will be useful to anybody other than me. So I'm posting it to GitHub Just In Case.
Here is how to use FileGenerator, with an example of how I actually use it to stream a WAV file as the WAV file is being written.
def live_martin_m2_renderer(image):
# Create a FileGenerator
generator = FileGenerator()
slowscan = MartinM2Generator(image, 48000, 16)
# Pass the FileGenerator to a thread that will start writing to the FileGenerator
MartinM2GeneratorWorker(slowscan, generator).start()
# Give the read_generator() to Flask, to stream the data as it is being written to the "file"
rv = Response(generator.read_generator(), mimetype='audio/wav')
rv.headers['Content-Length'] = 5661190
return rv