Skip to content

Instantly share code, notes, and snippets.

@chand1012
Last active September 6, 2021 04:37
Show Gist options
  • Save chand1012/97ad4d0623a71c30a46df96e72aa93d5 to your computer and use it in GitHub Desktop.
Save chand1012/97ad4d0623a71c30a46df96e72aa93d5 to your computer and use it in GitHub Desktop.
File to test the buffer size for os.read. Requires humanize to be installed. See here for license: https://chand1012.mit-license.org/
import os
import sys
import humanize
file_path = sys.argv[1]
size = os.path.getsize(file_path)
print(f'Size in bytes: {humanize.naturalsize(size, binary=True)}')
video = os.open(file_path, os.O_RDONLY)
video_buffer = os.read(video, size)
print(f'Video buffer size: {humanize.naturalsize(sys.getsizeof(video_buffer), binary=True)}')
# Call like so: python3 buffersize.py /path/to/file.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment