Skip to content

Instantly share code, notes, and snippets.

@dcwatson
dcwatson / range_streaming.py
Last active May 6, 2023 20:10
Django streaming view accepting byte range requests
from django.http import StreamingHttpResponse
from wsgiref.util import FileWrapper
import mimetypes
import os
import re
range_re = re.compile(r'bytes\s*=\s*(\d+)\s*-\s*(\d*)', re.I)
class RangeFileWrapper (object):
def __init__(self, filelike, blksize=8192, offset=0, length=None):