/* Generated by Cython 0.29.32 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [],
        "extra_compile_args": [
            "-std=c++17",
            "-O3",
            "-Wall",
            "-Wno-deprecated-declarations",
            "-Wno-unreachable-code",
            "-Wno-unused-function"
        ],
        "extra_link_args": [
            "-std=c++17"
        ],
        "language": "c++",
        "libraries": [
            "z",
            "lz4"
        ],
        "name": "fastwarc.stream_io",
        "sources": [
            "fastwarc/stream_io.pyx"
        ]
    },
    "module_name": "fastwarc.stream_io"
}
END: Cython Metadata */

#ifndef PY_SSIZE_T_CLEAN
#define PY_SSIZE_T_CLEAN
#endif /* PY_SSIZE_T_CLEAN */
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
    #error Cython requires Python 2.6+ or Python 3.3+.
#else
#define CYTHON_ABI "0_29_32"
#define CYTHON_HEX_VERSION 0x001D20F0
#define CYTHON_FUTURE_DIVISION 1
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #if PY_VERSION_HEX >= 0x02070000
    #define HAVE_LONG_LONG
  #endif
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC (PYPY_VERSION_HEX >= 0x07030900)
  #endif
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
#elif defined(PY_NOGIL)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #ifndef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #define CYTHON_COMPILING_IN_NOGIL 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 0
  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
    #define CYTHON_USE_PYTYPE_LOOKUP 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #if PY_VERSION_HEX >= 0x030B00A4
    #undef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 0
  #elif !defined(CYTHON_FAST_THREAD_STATE)
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL (PY_VERSION_HEX < 0x030A0000)
  #endif
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  #endif
  #ifndef CYTHON_USE_DICT_VERSIONS
    #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
  #endif
  #if PY_VERSION_HEX >= 0x030B00A4
    #undef CYTHON_USE_EXC_INFO_STACK
    #define CYTHON_USE_EXC_INFO_STACK 0
  #elif !defined(CYTHON_USE_EXC_INFO_STACK)
    #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
  #endif
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 1
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #if PY_MAJOR_VERSION < 3
    #include "longintrepr.h"
  #endif
  #undef SHIFT
  #undef BASE
  #undef MASK
  #ifdef SIZEOF_VOID_P
    enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
  #endif
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_MAYBE_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
           typedef unsigned char     uint8_t;
           typedef unsigned int      uint32_t;
        #else
           typedef unsigned __int8   uint8_t;
           typedef unsigned __int32  uint32_t;
        #endif
    #endif
#else
   #include <stdint.h>
#endif
#ifndef CYTHON_FALLTHROUGH
  #if defined(__cplusplus) && __cplusplus >= 201103L
    #if __has_cpp_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH [[fallthrough]]
    #elif __has_cpp_attribute(clang::fallthrough)
      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
    #elif __has_cpp_attribute(gnu::fallthrough)
      #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
  #if defined(__clang__ ) && defined(__apple_build_version__)
    #if __apple_build_version__ < 7000000
      #undef  CYTHON_FALLTHROUGH
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif

#ifndef __cplusplus
  #error "Cython files generated with the C++ option must be compiled with a C++ compiler."
#endif
#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #else
    #define CYTHON_INLINE inline
  #endif
#endif
template<typename T>
void __Pyx_call_destructor(T& x) {
    x.~T();
}
template<typename T>
class __Pyx_FakeReference {
  public:
    __Pyx_FakeReference() : ptr(NULL) { }
    __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
    T *operator->() { return ptr; }
    T *operator&() { return ptr; }
    operator T&() { return *ptr; }
    template<typename U> bool operator ==(U other) { return *ptr == other; }
    template<typename U> bool operator !=(U other) { return *ptr != other; }
  private:
    T *ptr;
};

#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_DefaultClassType PyType_Type
#if PY_VERSION_HEX >= 0x030B00A1
    static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int k, int l, int s, int f,
                                                    PyObject *code, PyObject *c, PyObject* n, PyObject *v,
                                                    PyObject *fv, PyObject *cell, PyObject* fn,
                                                    PyObject *name, int fline, PyObject *lnos) {
        PyObject *kwds=NULL, *argcount=NULL, *posonlyargcount=NULL, *kwonlyargcount=NULL;
        PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *call_result=NULL, *empty=NULL;
        const char *fn_cstr=NULL;
        const char *name_cstr=NULL;
        PyCodeObject* co=NULL;
        PyObject *type, *value, *traceback;
        PyErr_Fetch(&type, &value, &traceback);
        if (!(kwds=PyDict_New())) goto end;
        if (!(argcount=PyLong_FromLong(a))) goto end;
        if (PyDict_SetItemString(kwds, "co_argcount", argcount) != 0) goto end;
        if (!(posonlyargcount=PyLong_FromLong(0))) goto end;
        if (PyDict_SetItemString(kwds, "co_posonlyargcount", posonlyargcount) != 0) goto end;
        if (!(kwonlyargcount=PyLong_FromLong(k))) goto end;
        if (PyDict_SetItemString(kwds, "co_kwonlyargcount", kwonlyargcount) != 0) goto end;
        if (!(nlocals=PyLong_FromLong(l))) goto end;
        if (PyDict_SetItemString(kwds, "co_nlocals", nlocals) != 0) goto end;
        if (!(stacksize=PyLong_FromLong(s))) goto end;
        if (PyDict_SetItemString(kwds, "co_stacksize", stacksize) != 0) goto end;
        if (!(flags=PyLong_FromLong(f))) goto end;
        if (PyDict_SetItemString(kwds, "co_flags", flags) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_code", code) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_consts", c) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_names", n) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_varnames", v) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_freevars", fv) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_cellvars", cell) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_linetable", lnos) != 0) goto end;
        if (!(fn_cstr=PyUnicode_AsUTF8AndSize(fn, NULL))) goto end;
        if (!(name_cstr=PyUnicode_AsUTF8AndSize(name, NULL))) goto end;
        if (!(co = PyCode_NewEmpty(fn_cstr, name_cstr, fline))) goto end;
        if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto cleanup_code_too;
        if (!(empty = PyTuple_New(0))) goto cleanup_code_too; // unfortunately __pyx_empty_tuple isn't available here
        if (!(call_result = PyObject_Call(replace, empty, kwds))) goto cleanup_code_too;
        Py_XDECREF((PyObject*)co);
        co = (PyCodeObject*)call_result;
        call_result = NULL;
        if (0) {
            cleanup_code_too:
            Py_XDECREF((PyObject*)co);
            co = NULL;
        }
        end:
        Py_XDECREF(kwds);
        Py_XDECREF(argcount);
        Py_XDECREF(posonlyargcount);
        Py_XDECREF(kwonlyargcount);
        Py_XDECREF(nlocals);
        Py_XDECREF(stacksize);
        Py_XDECREF(replace);
        Py_XDECREF(call_result);
        Py_XDECREF(empty);
        if (type) {
            PyErr_Restore(type, value, traceback);
        }
        return co;
    }
#else
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#endif
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#ifndef METH_STACKLESS
  #define METH_STACKLESS 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 0
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
  #define PyMem_RawMalloc(n)           PyMem_Malloc(n)
  #define PyMem_RawRealloc(p, n)       PyMem_Realloc(p, n)
  #define PyMem_RawFree(p)             PyMem_Free(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03060000
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  *key = PyThread_create_key();
  return 0;
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  *key = Py_tss_NEEDS_INIT;
  return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  PyThread_delete_key(*key);
  *key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  return PyThread_get_key_value(*key);
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
#else
#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #if defined(PyUnicode_IS_READY)
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #else
  #define __Pyx_PyUnicode_READY(op)       (0)
  #endif
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
  #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length))
  #else
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  #endif
  #else
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
  #endif
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#ifndef PyObject_Unicode
  #define PyObject_Unicode             PyObject_Str
#endif
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#if PY_VERSION_HEX >= 0x030900A4
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
#else
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsHash_t
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
#endif

#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
  #if !defined(_USE_MATH_DEFINES)
    #define _USE_MATH_DEFINES
  #endif
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif

#define __PYX_MARK_ERR_POS(f_index, lineno) \
    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
#define __PYX_ERR(f_index, lineno, Ln_error) \
    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__fastwarc__stream_io
#define __PYX_HAVE_API__fastwarc__stream_io
/* Early includes */
#include <string.h>
#include <stdio.h>
#include <string>
#include "ios"
#include "new"
#include "stdexcept"
#include "typeinfo"
#include <zlib.h>
#include <lz4hc.h>
#include <lz4frame.h>
#include <string_view>

    /* Helper enum for keeping track of current compressing stream state. */
    enum CompressingStreamState {
        UNINIT = 0,
        DECOMPRESSING = 1,
        COMPRESSING = 2
    };
    
#include <cstring>
#include <errno.h>
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
#define CYTHON_WITHOUT_ASSERTIONS
#endif

typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
    return (size_t) i < (size_t) limit;
}
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
#if CYTHON_ASSUME_SAFE_MACROS
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

static PyObject *__pyx_m = NULL;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_cython_runtime = NULL;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "fastwarc/stream_io.pxd",
  "fastwarc/stream_io.pyx",
  "stringsource",
};
/* NoFastGil.proto */
#define __Pyx_PyGILState_Ensure PyGILState_Ensure
#define __Pyx_PyGILState_Release PyGILState_Release
#define __Pyx_FastGIL_Remember()
#define __Pyx_FastGIL_Forget()
#define __Pyx_FastGilFuncInit()

/* ForceInitThreads.proto */
#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif


/*--- Type declarations ---*/
struct __pyx_obj_8fastwarc_9stream_io_IOStream;
struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter;
struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream;
struct __pyx_obj_8fastwarc_9stream_io_FileStream;
struct __pyx_obj_8fastwarc_9stream_io_CompressingStream;
struct __pyx_obj_8fastwarc_9stream_io_GZipStream;
struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream;
struct __pyx_obj_8fastwarc_9stream_io_BrotliStream;
struct __pyx_obj_8fastwarc_9stream_io_BufferedReader;
struct __pyx_opt_args_8fastwarc_9stream_io_10FileStream_open;
struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_read;
struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_readline;
struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_consume;

/* "fastwarc/stream_io.pxd":76
 *     cdef FILE* fp
 * 
 *     cdef void open(self, const char* path, char* mode=*) except *             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_opt_args_8fastwarc_9stream_io_10FileStream_open {
  int __pyx_n;
  char *mode;
};

/* "fastwarc/stream_io.pxd":159
 *     cdef bint detect_stream_type(self) except 0
 * 
 *     cpdef string read(self, size_t size=*) except *             # <<<<<<<<<<<<<<
 *     cpdef string readline(self, bint crlf=*, size_t max_line_len=*)  except *
 *     cpdef size_t tell(self) except -1
 */
struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_read {
  int __pyx_n;
  size_t size;
};

/* "fastwarc/stream_io.pxd":160
 * 
 *     cpdef string read(self, size_t size=*) except *
 *     cpdef string readline(self, bint crlf=*, size_t max_line_len=*)  except *             # <<<<<<<<<<<<<<
 *     cpdef size_t tell(self) except -1
 *     cpdef size_t consume(self, size_t size=*) except -1
 */
struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_readline {
  int __pyx_n;
  int crlf;
  size_t max_line_len;
};

/* "fastwarc/stream_io.pxd":162
 *     cpdef string readline(self, bint crlf=*, size_t max_line_len=*)  except *
 *     cpdef size_t tell(self) except -1
 *     cpdef size_t consume(self, size_t size=*) except -1             # <<<<<<<<<<<<<<
 *     cpdef void close(self) except *
 * 
 */
struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_consume {
  int __pyx_n;
  size_t size;
};

/* "fastwarc/stream_io.pxd":25
 * 
 * 
 * cdef class IOStream:             # <<<<<<<<<<<<<<
 *     cdef size_t read(self, char* out, size_t size) except -1
 *     cdef size_t write(self, const char* data, size_t size) except -1
 */
struct __pyx_obj_8fastwarc_9stream_io_IOStream {
  PyObject_HEAD
  struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *__pyx_vtab;
};


/* "fastwarc/stream_io.pxd":35
 * 
 * # noinspection PyAttributeOutsideInit
 * cdef class PythonIOStreamAdapter(IOStream):             # <<<<<<<<<<<<<<
 *     cdef object py_stream
 * 
 */
struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream __pyx_base;
  PyObject *py_stream;
};


/* "fastwarc/stream_io.pxd":66
 * 
 * 
 * cdef class BytesIOStream(IOStream):             # <<<<<<<<<<<<<<
 *     cdef string buffer
 *     cdef size_t pos
 */
struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream __pyx_base;
  std::string buffer;
  size_t pos;
};


/* "fastwarc/stream_io.pxd":73
 * 
 * 
 * cdef class FileStream(IOStream):             # <<<<<<<<<<<<<<
 *     cdef FILE* fp
 * 
 */
struct __pyx_obj_8fastwarc_9stream_io_FileStream {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream __pyx_base;
  FILE *fp;
};


/* "fastwarc/stream_io.pxd":79
 * 
 * 
 * cdef class CompressingStream(IOStream):             # <<<<<<<<<<<<<<
 *     cdef size_t begin_member(self)
 *     cdef size_t end_member(self)
 */
struct __pyx_obj_8fastwarc_9stream_io_CompressingStream {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream __pyx_base;
};


/* "fastwarc/stream_io.pxd":99
 * 
 * 
 * cdef class GZipStream(CompressingStream):             # <<<<<<<<<<<<<<
 *     cdef IOStream raw_stream
 *     cdef string working_buf
 */
struct __pyx_obj_8fastwarc_9stream_io_GZipStream {
  struct __pyx_obj_8fastwarc_9stream_io_CompressingStream __pyx_base;
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *raw_stream;
  std::string working_buf;
  unsigned int working_buf_filled;
  z_stream zst;
  int window_bits;
  char stream_state;
  size_t stream_pos;
  int member_started;
  int compression_level;
};


/* "fastwarc/stream_io.pxd":117
 * 
 * 
 * cdef class LZ4Stream(CompressingStream):             # <<<<<<<<<<<<<<
 *     cdef IOStream raw_stream
 *     cdef LZ4F_cctx* cctx
 */
struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream {
  struct __pyx_obj_8fastwarc_9stream_io_CompressingStream __pyx_base;
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *raw_stream;
  LZ4F_cctx *cctx;
  LZ4F_dctx *dctx;
  LZ4F_preferences_t prefs;
  std::string working_buf;
  size_t working_buf_read;
  size_t working_buf_filled;
  int frame_started;
  size_t stream_pos;
};


/* "fastwarc/stream_io.pxd":132
 * 
 * 
 * cdef class BrotliStream(CompressingStream):             # <<<<<<<<<<<<<<
 *     cdef IOStream raw_stream
 *     cdef size_t quality
 */
struct __pyx_obj_8fastwarc_9stream_io_BrotliStream {
  struct __pyx_obj_8fastwarc_9stream_io_CompressingStream __pyx_base;
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *raw_stream;
  size_t quality;
  size_t lgwin;
  size_t lgblock;
  PyObject *compressor;
  std::string working_buf;
  CompressingStreamState stream_state;
};


/* "fastwarc/stream_io.pxd":142
 * 
 * 
 * cdef class BufferedReader:             # <<<<<<<<<<<<<<
 *     cdef IOStream stream
 *     cdef string errstr
 */
struct __pyx_obj_8fastwarc_9stream_io_BufferedReader {
  PyObject_HEAD
  struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader *__pyx_vtab;
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *stream;
  std::string errstr;
  std::string buf;
  std::string_view buf_view;
  std::string_view limited_buf_view;
  size_t stream_pos;
  size_t limit;
  size_t limit_consumed;
  int negotiate_stream;
  int stream_started;
  int stream_is_compressed;
};



/* "fastwarc/stream_io.pyx":42
 * 
 * @cython.auto_pickle(False)
 * cdef class IOStream:             # <<<<<<<<<<<<<<
 *     """IOStream base class."""
 * 
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream {
  size_t (*read)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char *, size_t);
  size_t (*write)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char const *, size_t);
  size_t (*tell)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *);
  void (*seek)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, size_t);
  void (*flush)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *);
  void (*close)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *);
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *__pyx_vtabptr_8fastwarc_9stream_io_IOStream;


/* "fastwarc/stream_io.pyx":261
 * 
 * @cython.auto_pickle(False)
 * cdef class PythonIOStreamAdapter(IOStream):             # <<<<<<<<<<<<<<
 *     """
 *     __init__(self, py_stream)
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_PythonIOStreamAdapter {
  struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream __pyx_base;
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_vtabptr_8fastwarc_9stream_io_PythonIOStreamAdapter;


/* "fastwarc/stream_io.pyx":132
 * # noinspection PyAttributeOutsideInit
 * @cython.auto_pickle(False)
 * cdef class BytesIOStream(IOStream):             # <<<<<<<<<<<<<<
 *     """
 *     __init__(self, initial_data=None)
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_BytesIOStream {
  struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream __pyx_base;
  std::string (*getvalue)(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *);
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_BytesIOStream *__pyx_vtabptr_8fastwarc_9stream_io_BytesIOStream;
static std::string __pyx_f_8fastwarc_9stream_io_13BytesIOStream_getvalue(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *);


/* "fastwarc/stream_io.pyx":189
 * # noinspection PyAttributeOutsideInit
 * @cython.auto_pickle(False)
 * cdef class FileStream(IOStream):             # <<<<<<<<<<<<<<
 *     """
 *     __init__(self, filename=None, mode='rb')
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_FileStream {
  struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream __pyx_base;
  void (*open)(struct __pyx_obj_8fastwarc_9stream_io_FileStream *, char const *, struct __pyx_opt_args_8fastwarc_9stream_io_10FileStream_open *__pyx_optional_args);
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_FileStream *__pyx_vtabptr_8fastwarc_9stream_io_FileStream;


/* "fastwarc/stream_io.pyx":297
 * 
 * @cython.auto_pickle(False)
 * cdef class CompressingStream(IOStream):             # <<<<<<<<<<<<<<
 *     """Base class for compressed :class:`IOStream` types."""
 * 
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_CompressingStream {
  struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream __pyx_base;
  size_t (*begin_member)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *);
  size_t (*end_member)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *);
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_CompressingStream *__pyx_vtabptr_8fastwarc_9stream_io_CompressingStream;


/* "fastwarc/stream_io.pyx":311
 * # noinspection PyAttributeOutsideInit
 * @cython.auto_pickle(False)
 * cdef class GZipStream(CompressingStream):             # <<<<<<<<<<<<<<
 *     """
 *     __init__(self, raw_stream, compression_level=9, zlib=False)
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream {
  struct __pyx_vtabstruct_8fastwarc_9stream_io_CompressingStream __pyx_base;
  void (*prepopulate)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *, int, std::string const &);
  void (*_init_z_stream)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *, int);
  void (*_free_z_stream)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *);
  void (*_reinit_z_stream)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *, int);
  int (*_refill_working_buf)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *, size_t);
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *__pyx_vtabptr_8fastwarc_9stream_io_GZipStream;


/* "fastwarc/stream_io.pyx":550
 * # noinspection PyAttributeOutsideInit
 * @cython.auto_pickle(False)
 * cdef class LZ4Stream(CompressingStream):             # <<<<<<<<<<<<<<
 *     """
 *     __init__(self, raw_stream, compression_level=12, favor_dec_speed=True)
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream {
  struct __pyx_vtabstruct_8fastwarc_9stream_io_CompressingStream __pyx_base;
  void (*prepopulate)(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *, std::string const &);
  void (*_free_ctx)(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *);
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream *__pyx_vtabptr_8fastwarc_9stream_io_LZ4Stream;


/* "fastwarc/stream_io.pyx":716
 * # noinspection PyAttributeOutsideInit
 * @cython.auto_pickle(False)
 * cdef class BrotliStream(CompressingStream):             # <<<<<<<<<<<<<<
 *     """
 *     __init__(self, raw_stream, quality=11, lgwin=22, lgblock=0)
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_BrotliStream {
  struct __pyx_vtabstruct_8fastwarc_9stream_io_CompressingStream __pyx_base;
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_BrotliStream *__pyx_vtabptr_8fastwarc_9stream_io_BrotliStream;


/* "fastwarc/stream_io.pyx":806
 * # noinspection PyAttributeOutsideInit
 * @cython.auto_pickle(False)
 * cdef class BufferedReader:             # <<<<<<<<<<<<<<
 *     """
 *     __init__(self, stream, buf_size=16384, negotiate_stream=True)
 */

struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader {
  void (*set_limit)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, size_t);
  void (*reset_limit)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *);
  int (*detect_stream_type)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *);
  std::string (*read)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_read *__pyx_optional_args);
  std::string (*readline)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_readline *__pyx_optional_args);
  size_t (*tell)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch);
  size_t (*consume)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_consume *__pyx_optional_args);
  void (*close)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch);
  int (*_fill_buf)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *);
  std::string_view *(*_get_buf)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *);
  size_t (*_consume_buf)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, size_t);
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader *__pyx_vtabptr_8fastwarc_9stream_io_BufferedReader;
static CYTHON_INLINE void __pyx_f_8fastwarc_9stream_io_14BufferedReader_set_limit(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, size_t);
static CYTHON_INLINE void __pyx_f_8fastwarc_9stream_io_14BufferedReader_reset_limit(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *);
static CYTHON_INLINE std::string_view *__pyx_f_8fastwarc_9stream_io_14BufferedReader__get_buf(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *);
static CYTHON_INLINE size_t __pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, size_t);

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* RaiseArgTupleInvalid.proto */
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

/* ArgTypeTest.proto */
#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
    ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\
        __Pyx__ArgTypeTest(obj, type, name, exact))
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);

/* PyCFunctionFastCall.proto */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
#else
#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
#endif

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#define __Pyx_BUILD_ASSERT_EXPR(cond)\
    (sizeof(char [1 - 2*!(cond)]) - 1)
#ifndef Py_MEMBER_SIZE
#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#endif
#if CYTHON_FAST_PYCALL
  static size_t __pyx_pyframe_localsplus_offset = 0;
  #include "frameobject.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
  #define __Pxy_PyFrame_Initialize_Offsets()\
    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
     (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
  #define __Pyx_PyFrame_GetLocalsplus(frame)\
    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
#endif // CYTHON_FAST_PYCALL
#endif

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* KeywordStringCheck.proto */
static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed);

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
#define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred()  PyErr_Occurred()
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

/* PyDictVersioning.proto */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
    (version_var) = __PYX_GET_DICT_VERSION(dict);\
    (cache_var) = (value);
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
        (VAR) = __pyx_dict_cached_value;\
    } else {\
        (VAR) = __pyx_dict_cached_value = (LOOKUP);\
        __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
    }\
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
#else
#define __PYX_GET_DICT_VERSION(dict)  (0)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
#endif

/* GetModuleGlobalName.proto */
#if CYTHON_USE_DICT_VERSIONS
#define __Pyx_GetModuleGlobalName(var, name)  {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
}
#define __Pyx_GetModuleGlobalNameUncached(var, name)  {\
    PY_UINT64_T __pyx_dict_version;\
    PyObject *__pyx_dict_cached_value;\
    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
}
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
#else
#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
#endif

/* IncludeStringH.proto */
#include <string.h>

/* decode_c_string_utf16.proto */
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = 0;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = -1;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) {
    int byteorder = 1;
    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
}

/* decode_c_string.proto */
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));

/* PyObjectCall2Args.proto */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);

/* ExtTypeTest.proto */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

/* GetAttr.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

/* HasAttr.proto */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);

/* PyObjectFormatSimple.proto */
#if CYTHON_COMPILING_IN_PYPY
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        PyObject_Format(s, f))
#elif PY_MAJOR_VERSION < 3
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\
        PyObject_Format(s, f))
#elif CYTHON_USE_TYPE_SLOTS
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) :\
        likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) :\
        PyObject_Format(s, f))
#else
    #define __Pyx_PyObject_FormatSimple(s, f) (\
        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
        PyObject_Format(s, f))
#endif

/* JoinPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      Py_UCS4 max_char);

/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

/* GetTopmostException.proto */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
#endif

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* PyErrExceptionMatches.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* CallNextTpTraverse.proto */
static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse);

/* CallNextTpClear.proto */
static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_dealloc);

/* PyObject_GenericGetAttrNoDict.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
#endif

/* PyObject_GenericGetAttr.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
#endif

/* SetVTable.proto */
static int __Pyx_SetVtable(PyObject *dict, void *vtable);

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* CalculateMetaclass.proto */
static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);

/* Py3ClassCreate.proto */
static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
                                           PyObject *mkw, PyObject *modname, PyObject *doc);
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
                                      PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass);

/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#endif

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* None.proto */
#include <new>

/* GCCDiagnostics.proto */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define __Pyx_HAS_GCC_DIAGNOSTIC
#endif

/* CppExceptionConversion.proto */
#ifndef __Pyx_CppExn2PyErr
#include <new>
#include <typeinfo>
#include <stdexcept>
#include <ios>
static void __Pyx_CppExn2PyErr() {
  try {
    if (PyErr_Occurred())
      ; // let the latest Python exn pass through and ignore the current one
    else
      throw;
  } catch (const std::bad_alloc& exn) {
    PyErr_SetString(PyExc_MemoryError, exn.what());
  } catch (const std::bad_cast& exn) {
    PyErr_SetString(PyExc_TypeError, exn.what());
  } catch (const std::bad_typeid& exn) {
    PyErr_SetString(PyExc_TypeError, exn.what());
  } catch (const std::domain_error& exn) {
    PyErr_SetString(PyExc_ValueError, exn.what());
  } catch (const std::invalid_argument& exn) {
    PyErr_SetString(PyExc_ValueError, exn.what());
  } catch (const std::ios_base::failure& exn) {
    PyErr_SetString(PyExc_IOError, exn.what());
  } catch (const std::out_of_range& exn) {
    PyErr_SetString(PyExc_IndexError, exn.what());
  } catch (const std::overflow_error& exn) {
    PyErr_SetString(PyExc_OverflowError, exn.what());
  } catch (const std::range_error& exn) {
    PyErr_SetString(PyExc_ArithmeticError, exn.what());
  } catch (const std::underflow_error& exn) {
    PyErr_SetString(PyExc_ArithmeticError, exn.what());
  } catch (const std::exception& exn) {
    PyErr_SetString(PyExc_RuntimeError, exn.what());
  }
  catch (...)
  {
    PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
  }
}
#endif

/* CIntFromPy.proto */
static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static size_t __pyx_f_8fastwarc_9stream_io_8IOStream_read(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self, CYTHON_UNUSED char *__pyx_v_out, CYTHON_UNUSED size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_8IOStream_write(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self, CYTHON_UNUSED char const *__pyx_v_data, CYTHON_UNUSED size_t __pyx_v_size); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_8IOStream_seek(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self, CYTHON_UNUSED size_t __pyx_v_offset); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_8IOStream_tell(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_8IOStream_flush(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_8IOStream_close(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_13BytesIOStream_tell(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_13BytesIOStream_seek(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, size_t __pyx_v_offset); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_13BytesIOStream_read(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_13BytesIOStream_write(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_13BytesIOStream_close(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self); /* proto*/
static std::string __pyx_f_8fastwarc_9stream_io_13BytesIOStream_getvalue(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10FileStream_open(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, char *__pyx_v_path, struct __pyx_opt_args_8fastwarc_9stream_io_10FileStream_open *__pyx_optional_args); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10FileStream_seek(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, size_t __pyx_v_offset); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_10FileStream_tell(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_10FileStream_read(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_10FileStream_write(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10FileStream_flush(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10FileStream_close(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_17CompressingStream_begin_member(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_17CompressingStream_end_member(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_tell(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10GZipStream__init_z_stream(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, int __pyx_v_deflate); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10GZipStream_prepopulate(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, int __pyx_v_deflate, std::string const &__pyx_v_initial_data); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10GZipStream__free_z_stream(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10GZipStream__reinit_z_stream(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, int __pyx_v_deflate); /* proto*/
static int __pyx_f_8fastwarc_9stream_io_10GZipStream__refill_working_buf(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_read(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_write(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_begin_member(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_end_member(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10GZipStream_flush(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_10GZipStream_close(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_tell(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_9LZ4Stream_prepopulate(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, std::string const &__pyx_v_initial_data); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_read(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_begin_member(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_end_member(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_write(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_9LZ4Stream_flush(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_9LZ4Stream_close(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_9LZ4Stream__free_ctx(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_begin_member(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_end_member(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_read(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_write(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_tell(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_12BrotliStream_seek(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, size_t __pyx_v_offset); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_12BrotliStream_flush(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_12BrotliStream_close(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self); /* proto*/
static int __pyx_f_8fastwarc_9stream_io_14BufferedReader_detect_stream_type(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self); /* proto*/
static int __pyx_f_8fastwarc_9stream_io_14BufferedReader__fill_buf(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self); /* proto*/
static CYTHON_INLINE std::string_view *__pyx_f_8fastwarc_9stream_io_14BufferedReader__get_buf(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self); /* proto*/
static CYTHON_INLINE size_t __pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, size_t __pyx_v_size); /* proto*/
static CYTHON_INLINE void __pyx_f_8fastwarc_9stream_io_14BufferedReader_set_limit(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, size_t __pyx_v_offset); /* proto*/
static CYTHON_INLINE void __pyx_f_8fastwarc_9stream_io_14BufferedReader_reset_limit(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self); /* proto*/
static std::string __pyx_f_8fastwarc_9stream_io_14BufferedReader_read(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_read *__pyx_optional_args); /* proto*/
static std::string __pyx_f_8fastwarc_9stream_io_14BufferedReader_readline(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_readline *__pyx_optional_args); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_14BufferedReader_tell(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_14BufferedReader_consume(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_consume *__pyx_optional_args); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_14BufferedReader_close(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_read(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_write(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size); /* proto*/
static size_t __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_tell(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_seek(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, size_t __pyx_v_offset); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_flush(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self); /* proto*/
static void __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_close(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self); /* proto*/

/* Module declarations from 'libc.string' */

/* Module declarations from 'libc.stdio' */

/* Module declarations from 'libcpp.string' */

/* Module declarations from 'resiliparse_inc.zlib' */

/* Module declarations from 'resiliparse_inc.lz4hc' */

/* Module declarations from 'resiliparse_inc.lz4frame' */

/* Module declarations from 'resiliparse_inc.string_view' */

/* Module declarations from 'cython' */

/* Module declarations from 'resiliparse_inc.cstring' */

/* Module declarations from 'resiliparse_inc.errno' */

/* Module declarations from 'resiliparse_inc.stdio' */

/* Module declarations from 'fastwarc.stream_io' */
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_IOStream = 0;
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_PythonIOStreamAdapter = 0;
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_BytesIOStream = 0;
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_FileStream = 0;
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_CompressingStream = 0;
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_GZipStream = 0;
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_LZ4Stream = 0;
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_BrotliStream = 0;
static PyTypeObject *__pyx_ptype_8fastwarc_9stream_io_BufferedReader = 0;
static struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_f_8fastwarc_9stream_io_wrap_stream(PyObject *, int __pyx_skip_dispatch); /*proto*/
static std::string __pyx_convert_string_from_py_std__in_string(PyObject *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_convert_PyObject_string_to_py_std__in_string(std::string const &); /*proto*/
static CYTHON_INLINE PyObject *__pyx_convert_PyUnicode_string_to_py_std__in_string(std::string const &); /*proto*/
static CYTHON_INLINE PyObject *__pyx_convert_PyStr_string_to_py_std__in_string(std::string const &); /*proto*/
static CYTHON_INLINE PyObject *__pyx_convert_PyBytes_string_to_py_std__in_string(std::string const &); /*proto*/
static CYTHON_INLINE PyObject *__pyx_convert_PyByteArray_string_to_py_std__in_string(std::string const &); /*proto*/
#define __Pyx_MODULE_NAME "fastwarc.stream_io"
extern int __pyx_module_is_main_fastwarc__stream_io;
int __pyx_module_is_main_fastwarc__stream_io = 0;

/* Implementation of 'fastwarc.stream_io' */
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_object;
static const char __pyx_k_rb[] = "rb";
static const char __pyx_k_buf[] = "buf";
static const char __pyx_k_doc[] = "__doc__";
static const char __pyx_k_crlf[] = "crlf";
static const char __pyx_k_data[] = "data";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_mode[] = "mode";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_read[] = "read";
static const char __pyx_k_seek[] = "seek";
static const char __pyx_k_size[] = "size";
static const char __pyx_k_tell[] = "tell";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_zlib[] = "zlib";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_error[] = "error";
static const char __pyx_k_flush[] = "flush";
static const char __pyx_k_lgwin[] = "lgwin";
static const char __pyx_k_limit[] = "limit";
static const char __pyx_k_write[] = "write";
static const char __pyx_k_brotli[] = "brotli";
static const char __pyx_k_exc_tb[] = "exc_tb";
static const char __pyx_k_finish[] = "finish";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_module[] = "__module__";
static const char __pyx_k_object[] = "object";
static const char __pyx_k_offset[] = "offset";
static const char __pyx_k_stream[] = "stream";
static const char __pyx_k_consume[] = "consume";
static const char __pyx_k_exc_val[] = "exc_val";
static const char __pyx_k_lgblock[] = "lgblock";
static const char __pyx_k_prepare[] = "__prepare__";
static const char __pyx_k_process[] = "process";
static const char __pyx_k_quality[] = "quality";
static const char __pyx_k_IOStream[] = "IOStream";
static const char __pyx_k_buf_size[] = "buf_size";
static const char __pyx_k_exc_type[] = "exc_type";
static const char __pyx_k_filename[] = "filename";
static const char __pyx_k_qualname[] = "__qualname__";
static const char __pyx_k_readline[] = "readline";
static const char __pyx_k_LZ4Stream[] = "LZ4Stream";
static const char __pyx_k_metaclass[] = "__metaclass__";
static const char __pyx_k_py_stream[] = "py_stream";
static const char __pyx_k_Compressor[] = "Compressor";
static const char __pyx_k_FileStream[] = "FileStream";
static const char __pyx_k_GZipStream[] = "GZipStream";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_raw_stream[] = "raw_stream";
static const char __pyx_k_StreamError[] = "StreamError";
static const char __pyx_k_BrotliStream[] = "BrotliStream";
static const char __pyx_k_Decompressor[] = "Decompressor";
static const char __pyx_k_initial_data[] = "initial_data";
static const char __pyx_k_max_line_len[] = "max_line_len";
static const char __pyx_k_BytesIOStream[] = "BytesIOStream";
static const char __pyx_k_FastWARCError[] = "FastWARCError";
static const char __pyx_k_BufferedReader[] = "BufferedReader";
static const char __pyx_k_Object_of_type[] = "Object of type '";
static const char __pyx_k_favor_dec_speed[] = "favor_dec_speed";
static const char __pyx_k_ReaderStaleError[] = "ReaderStaleError";
static const char __pyx_k_negotiate_stream[] = "negotiate_stream";
static const char __pyx_k_CompressingStream[] = "CompressingStream";
static const char __pyx_k_compression_level[] = "compression_level";
static const char __pyx_k_Error_reading_file[] = "Error reading file";
static const char __pyx_k_Error_writing_file[] = "Error writing file";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_fastwarc_stream_io[] = "fastwarc.stream_io";
static const char __pyx_k_FastWARC_stream_error[] = "FastWARC stream error.";
static const char __pyx_k_PythonIOStreamAdapter[] = "PythonIOStreamAdapter";
static const char __pyx_k_is_not_a_valid_stream[] = "' is not a valid stream.";
static const char __pyx_k_Not_a_valid_LZ4_stream[] = "Not a valid LZ4 stream: ";
static const char __pyx_k_fastwarc_stream_io_pyx[] = "fastwarc/stream_io.pyx";
static const char __pyx_k_io_stream_py_test_read[] = "_io_stream_py_test_read";
static const char __pyx_k_io_stream_py_test_seek[] = "_io_stream_py_test_seek";
static const char __pyx_k_io_stream_py_test_tell[] = "_io_stream_py_test_tell";
static const char __pyx_k_Compression_in_progress[] = "Compression in progress.";
static const char __pyx_k_Not_a_valid_GZip_stream[] = "Not a valid GZip stream";
static const char __pyx_k_Not_a_valid_WARC_stream[] = "Not a valid WARC stream";
static const char __pyx_k_io_stream_py_test_close[] = "_io_stream_py_test_close";
static const char __pyx_k_io_stream_py_test_flush[] = "_io_stream_py_test_flush";
static const char __pyx_k_io_stream_py_test_write[] = "_io_stream_py_test_write";
static const char __pyx_k_Decompression_in_progress[] = "Decompression in progress";
static const char __pyx_k_Not_a_valid_Brotli_stream[] = "Not a valid Brotli stream";
static const char __pyx_k_Trying_I_O_on_closed_file[] = "Trying I/O on closed file.";
static const char __pyx_k_Generic_FastWARC_exception[] = "Generic FastWARC exception.";
static const char __pyx_k_Decompression_in_progress_2[] = "Decompression in progress.";
static const char __pyx_k_FastWARC_reader_stale_error[] = "FastWARC reader stale error.";
static const char __pyx_k_buf_reader_py_test_set_limit[] = "_buf_reader_py_test_set_limit";
static const char __pyx_k_buf_reader_py_test_reset_limit[] = "_buf_reader_py_test_reset_limit";
static const char __pyx_k_buf_reader_py_test_detect_strea[] = "_buf_reader_py_test_detect_stream_type";
static const char __pyx_k_Failed_to_create_compression_con[] = "Failed to create compression context: ";
static PyObject *__pyx_n_s_BrotliStream;
static PyObject *__pyx_n_s_BufferedReader;
static PyObject *__pyx_n_s_BytesIOStream;
static PyObject *__pyx_n_s_CompressingStream;
static PyObject *__pyx_kp_u_Compression_in_progress;
static PyObject *__pyx_n_s_Compressor;
static PyObject *__pyx_kp_u_Decompression_in_progress;
static PyObject *__pyx_kp_u_Decompression_in_progress_2;
static PyObject *__pyx_n_s_Decompressor;
static PyObject *__pyx_kp_u_Error_reading_file;
static PyObject *__pyx_kp_u_Error_writing_file;
static PyObject *__pyx_kp_u_Failed_to_create_compression_con;
static PyObject *__pyx_n_s_FastWARCError;
static PyObject *__pyx_kp_s_FastWARC_reader_stale_error;
static PyObject *__pyx_kp_s_FastWARC_stream_error;
static PyObject *__pyx_n_s_FileStream;
static PyObject *__pyx_n_s_GZipStream;
static PyObject *__pyx_kp_s_Generic_FastWARC_exception;
static PyObject *__pyx_n_s_IOStream;
static PyObject *__pyx_n_s_LZ4Stream;
static PyObject *__pyx_kp_u_Not_a_valid_Brotli_stream;
static PyObject *__pyx_kp_u_Not_a_valid_GZip_stream;
static PyObject *__pyx_kp_u_Not_a_valid_LZ4_stream;
static PyObject *__pyx_kp_u_Not_a_valid_WARC_stream;
static PyObject *__pyx_kp_u_Object_of_type;
static PyObject *__pyx_n_s_PythonIOStreamAdapter;
static PyObject *__pyx_n_s_ReaderStaleError;
static PyObject *__pyx_n_s_StreamError;
static PyObject *__pyx_kp_u_Trying_I_O_on_closed_file;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_brotli;
static PyObject *__pyx_n_s_buf;
static PyObject *__pyx_n_s_buf_reader_py_test_detect_strea;
static PyObject *__pyx_n_s_buf_reader_py_test_reset_limit;
static PyObject *__pyx_n_s_buf_reader_py_test_set_limit;
static PyObject *__pyx_n_s_buf_size;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_compression_level;
static PyObject *__pyx_n_s_consume;
static PyObject *__pyx_n_s_crlf;
static PyObject *__pyx_n_s_data;
static PyObject *__pyx_n_s_doc;
static PyObject *__pyx_n_s_error;
static PyObject *__pyx_n_s_exc_tb;
static PyObject *__pyx_n_s_exc_type;
static PyObject *__pyx_n_s_exc_val;
static PyObject *__pyx_n_s_fastwarc_stream_io;
static PyObject *__pyx_kp_s_fastwarc_stream_io_pyx;
static PyObject *__pyx_n_s_favor_dec_speed;
static PyObject *__pyx_n_s_filename;
static PyObject *__pyx_n_s_finish;
static PyObject *__pyx_n_s_flush;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_initial_data;
static PyObject *__pyx_n_s_io_stream_py_test_close;
static PyObject *__pyx_n_s_io_stream_py_test_flush;
static PyObject *__pyx_n_s_io_stream_py_test_read;
static PyObject *__pyx_n_s_io_stream_py_test_seek;
static PyObject *__pyx_n_s_io_stream_py_test_tell;
static PyObject *__pyx_n_s_io_stream_py_test_write;
static PyObject *__pyx_kp_u_is_not_a_valid_stream;
static PyObject *__pyx_n_s_lgblock;
static PyObject *__pyx_n_s_lgwin;
static PyObject *__pyx_n_s_limit;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_max_line_len;
static PyObject *__pyx_n_s_metaclass;
static PyObject *__pyx_n_s_mode;
static PyObject *__pyx_n_s_module;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_negotiate_stream;
static PyObject *__pyx_n_s_object;
static PyObject *__pyx_n_s_offset;
static PyObject *__pyx_n_s_prepare;
static PyObject *__pyx_n_s_process;
static PyObject *__pyx_n_s_py_stream;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_quality;
static PyObject *__pyx_n_s_qualname;
static PyObject *__pyx_n_s_raw_stream;
static PyObject *__pyx_n_u_rb;
static PyObject *__pyx_n_s_read;
static PyObject *__pyx_n_u_read;
static PyObject *__pyx_n_s_readline;
static PyObject *__pyx_n_s_seek;
static PyObject *__pyx_n_s_size;
static PyObject *__pyx_n_s_stream;
static PyObject *__pyx_n_s_tell;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_write;
static PyObject *__pyx_n_s_zlib;
static struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_pf_8fastwarc_9stream_io_8IOStream___enter__(struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_8IOStream_2__exit__(struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_val, CYTHON_UNUSED PyObject *__pyx_v_exc_tb); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io__io_stream_py_test_read(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream, size_t __pyx_v_size); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_2_io_stream_py_test_write(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream, PyObject *__pyx_v_data); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_4_io_stream_py_test_tell(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_6_io_stream_py_test_seek(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream, size_t __pyx_v_offset); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_8_io_stream_py_test_flush(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_10_io_stream_py_test_close(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_13BytesIOStream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_13BytesIOStream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, PyObject *__pyx_v_initial_data); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_10FileStream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_10FileStream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode); /* proto */
static void __pyx_pf_8fastwarc_9stream_io_10FileStream_4__dealloc__(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_21PythonIOStreamAdapter___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_21PythonIOStreamAdapter_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, PyObject *__pyx_v_py_stream); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_12wrap_stream(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_raw_stream); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_10GZipStream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_10GZipStream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, PyObject *__pyx_v_raw_stream, PyObject *__pyx_v_compression_level, int __pyx_v_zlib); /* proto */
static void __pyx_pf_8fastwarc_9stream_io_10GZipStream_4__dealloc__(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_9LZ4Stream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_9LZ4Stream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, PyObject *__pyx_v_raw_stream, PyObject *__pyx_v_compression_level, PyObject *__pyx_v_favor_dec_speed); /* proto */
static void __pyx_pf_8fastwarc_9stream_io_9LZ4Stream_4__dealloc__(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_12BrotliStream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_12BrotliStream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, PyObject *__pyx_v_raw_stream, size_t __pyx_v_quality, size_t __pyx_v_lgwin, size_t __pyx_v_lgblock); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_14BufferedReader___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_8fastwarc_9stream_io_14BufferedReader_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream, size_t __pyx_v_buf_size, int __pyx_v_negotiate_stream); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_4read(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, size_t __pyx_v_size); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_6readline(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_v_crlf, size_t __pyx_v_max_line_len); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_8tell(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_10consume(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, size_t __pyx_v_size); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_12close(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_14_buf_reader_py_test_detect_stream_type(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_buf); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_16_buf_reader_py_test_set_limit(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_buf, size_t __pyx_v_limit); /* proto */
static PyObject *__pyx_pf_8fastwarc_9stream_io_18_buf_reader_py_test_reset_limit(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_buf); /* proto */
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_IOStream(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_PythonIOStreamAdapter(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_BytesIOStream(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_FileStream(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_CompressingStream(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_GZipStream(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_LZ4Stream(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_BrotliStream(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8fastwarc_9stream_io_BufferedReader(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_k__2;
static PyObject *__pyx_k__3;
static size_t __pyx_k__4;
static size_t __pyx_k__5;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_codeobj__7;
static PyObject *__pyx_codeobj__9;
static PyObject *__pyx_codeobj__11;
static PyObject *__pyx_codeobj__13;
static PyObject *__pyx_codeobj__15;
static PyObject *__pyx_codeobj__17;
static PyObject *__pyx_codeobj__19;
static PyObject *__pyx_codeobj__21;
static PyObject *__pyx_codeobj__23;
/* Late includes */

/* "fastwarc/stream_io.pyx":45
 *     """IOStream base class."""
 * 
 *     def __enter__(self) -> IOStream:             # <<<<<<<<<<<<<<
 *         """
 *         :rtype: IOStream
 */

/* Python wrapper */
static struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_pw_8fastwarc_9stream_io_8IOStream_1__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_8IOStream___enter__[] = "\n        :rtype: IOStream\n        ";
static struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_pw_8fastwarc_9stream_io_8IOStream_1__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_8IOStream___enter__(((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_pf_8fastwarc_9stream_io_8IOStream___enter__(struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self) {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__enter__", 0);

  /* "fastwarc/stream_io.pyx":49
 *         :rtype: IOStream
 *         """
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def __exit__(self, exc_type, exc_val, exc_tb):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":45
 *     """IOStream base class."""
 * 
 *     def __enter__(self) -> IOStream:             # <<<<<<<<<<<<<<
 *         """
 *         :rtype: IOStream
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":51
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_val, exc_tb):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_8IOStream_3__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_8fastwarc_9stream_io_8IOStream_3__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0;
  CYTHON_UNUSED PyObject *__pyx_v_exc_val = 0;
  CYTHON_UNUSED PyObject *__pyx_v_exc_tb = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exc_type,&__pyx_n_s_exc_val,&__pyx_n_s_exc_tb,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_val)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(1, 51, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_tb)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(1, 51, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(1, 51, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_exc_type = values[0];
    __pyx_v_exc_val = values[1];
    __pyx_v_exc_tb = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 51, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.IOStream.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_8IOStream_2__exit__(((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_val, __pyx_v_exc_tb);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_8IOStream_2__exit__(struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_val, CYTHON_UNUSED PyObject *__pyx_v_exc_tb) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__exit__", 0);

  /* "fastwarc/stream_io.pyx":52
 * 
 *     def __exit__(self, exc_type, exc_val, exc_tb):
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->__pyx_vtab)->close(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 52, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":51
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_val, exc_tb):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.IOStream.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":54
 *         self.close()
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_8IOStream_read(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self, CYTHON_UNUSED char *__pyx_v_out, CYTHON_UNUSED size_t __pyx_v_size) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("read", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":57
 *         pass
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_8IOStream_write(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self, CYTHON_UNUSED char const *__pyx_v_data, CYTHON_UNUSED size_t __pyx_v_size) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":60
 *         pass
 * 
 *     cdef void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static void __pyx_f_8fastwarc_9stream_io_8IOStream_seek(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self, CYTHON_UNUSED size_t __pyx_v_offset) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("seek", 0);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":63
 *         pass
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_8IOStream_tell(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("tell", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":66
 *         pass
 * 
 *     cdef void flush(self) except *:             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static void __pyx_f_8fastwarc_9stream_io_8IOStream_flush(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("flush", 0);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":69
 *         pass
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static void __pyx_f_8fastwarc_9stream_io_8IOStream_close(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close", 0);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":73
 * 
 * 
 * def _io_stream_py_test_read(IOStream stream, size_t size):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_read(stream, size)
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_1_io_stream_py_test_read(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io__io_stream_py_test_read[] = "\n    io_stream_py_test_read(stream, size)\n\n    Test interface for :meth:`IOStream.read`.\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_1_io_stream_py_test_read = {"_io_stream_py_test_read", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8fastwarc_9stream_io_1_io_stream_py_test_read, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8fastwarc_9stream_io__io_stream_py_test_read};
static PyObject *__pyx_pw_8fastwarc_9stream_io_1_io_stream_py_test_read(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream = 0;
  size_t __pyx_v_size;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_io_stream_py_test_read (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stream,&__pyx_n_s_size,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stream)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_size)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_io_stream_py_test_read", 1, 2, 2, 1); __PYX_ERR(1, 73, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_io_stream_py_test_read") < 0)) __PYX_ERR(1, 73, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)values[0]);
    __pyx_v_size = __Pyx_PyInt_As_size_t(values[1]); if (unlikely((__pyx_v_size == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 73, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_io_stream_py_test_read", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 73, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stream), __pyx_ptype_8fastwarc_9stream_io_IOStream, 1, "stream", 0))) __PYX_ERR(1, 73, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io__io_stream_py_test_read(__pyx_self, __pyx_v_stream, __pyx_v_size);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io__io_stream_py_test_read(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream, size_t __pyx_v_size) {
  PyObject *__pyx_v_buf = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  size_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_io_stream_py_test_read", 0);

  /* "fastwarc/stream_io.pyx":79
 *     Test interface for :meth:`IOStream.read`.
 *     """
 *     cdef bytearray buf = bytearray(size)             # <<<<<<<<<<<<<<
 *     size = stream.read(<char*>buf, size)
 *     return buf[:size], size
 */
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 79, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 79, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_buf = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "fastwarc/stream_io.pyx":80
 *     """
 *     cdef bytearray buf = bytearray(size)
 *     size = stream.read(<char*>buf, size)             # <<<<<<<<<<<<<<
 *     return buf[:size], size
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_buf); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(1, 80, __pyx_L1_error)
  __pyx_t_4 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_stream->__pyx_vtab)->read(__pyx_v_stream, ((char *)__pyx_t_3), __pyx_v_size); if (unlikely(__pyx_t_4 == ((size_t)-1L))) __PYX_ERR(1, 80, __pyx_L1_error)
  __pyx_v_size = __pyx_t_4;

  /* "fastwarc/stream_io.pyx":81
 *     cdef bytearray buf = bytearray(size)
 *     size = stream.read(<char*>buf, size)
 *     return buf[:size], size             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PySequence_GetSlice(__pyx_v_buf, 0, __pyx_v_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 81, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 81, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 81, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  __pyx_t_2 = 0;
  __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":73
 * 
 * 
 * def _io_stream_py_test_read(IOStream stream, size_t size):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_read(stream, size)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_buf);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":84
 * 
 * 
 * def _io_stream_py_test_write(IOStream stream, bytes data):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_write(stream, data)
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_3_io_stream_py_test_write(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_2_io_stream_py_test_write[] = "\n    io_stream_py_test_write(stream, data)\n\n    Test interface for :meth:`IOStream.write`.\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_3_io_stream_py_test_write = {"_io_stream_py_test_write", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8fastwarc_9stream_io_3_io_stream_py_test_write, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8fastwarc_9stream_io_2_io_stream_py_test_write};
static PyObject *__pyx_pw_8fastwarc_9stream_io_3_io_stream_py_test_write(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream = 0;
  PyObject *__pyx_v_data = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_io_stream_py_test_write (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stream,&__pyx_n_s_data,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stream)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_io_stream_py_test_write", 1, 2, 2, 1); __PYX_ERR(1, 84, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_io_stream_py_test_write") < 0)) __PYX_ERR(1, 84, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)values[0]);
    __pyx_v_data = ((PyObject*)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_io_stream_py_test_write", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 84, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stream), __pyx_ptype_8fastwarc_9stream_io_IOStream, 1, "stream", 0))) __PYX_ERR(1, 84, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyBytes_Type), 1, "data", 1))) __PYX_ERR(1, 84, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_2_io_stream_py_test_write(__pyx_self, __pyx_v_stream, __pyx_v_data);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_2_io_stream_py_test_write(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream, PyObject *__pyx_v_data) {
  size_t __pyx_v_size;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  char const *__pyx_t_1;
  Py_ssize_t __pyx_t_2;
  size_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_io_stream_py_test_write", 0);

  /* "fastwarc/stream_io.pyx":90
 *     Test interface for :meth:`IOStream.write`.
 *     """
 *     size = stream.write(<const char*>data, len(data))             # <<<<<<<<<<<<<<
 *     return size
 * 
 */
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
    __PYX_ERR(1, 90, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_data); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(1, 90, __pyx_L1_error)
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(1, 90, __pyx_L1_error)
  }
  __pyx_t_2 = PyBytes_GET_SIZE(__pyx_v_data); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(1, 90, __pyx_L1_error)
  __pyx_t_3 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_stream->__pyx_vtab)->write(__pyx_v_stream, ((char const *)__pyx_t_1), __pyx_t_2); if (unlikely(__pyx_t_3 == ((size_t)-1L))) __PYX_ERR(1, 90, __pyx_L1_error)
  __pyx_v_size = __pyx_t_3;

  /* "fastwarc/stream_io.pyx":91
 *     """
 *     size = stream.write(<const char*>data, len(data))
 *     return size             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyInt_FromSize_t(__pyx_v_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 91, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":84
 * 
 * 
 * def _io_stream_py_test_write(IOStream stream, bytes data):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_write(stream, data)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":94
 * 
 * 
 * def _io_stream_py_test_tell(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_tell(stream)
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_5_io_stream_py_test_tell(PyObject *__pyx_self, PyObject *__pyx_v_stream); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_4_io_stream_py_test_tell[] = "\n    io_stream_py_test_tell(stream)\n\n    Test interface for :meth:`IOStream.tell`.\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_5_io_stream_py_test_tell = {"_io_stream_py_test_tell", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_5_io_stream_py_test_tell, METH_O, __pyx_doc_8fastwarc_9stream_io_4_io_stream_py_test_tell};
static PyObject *__pyx_pw_8fastwarc_9stream_io_5_io_stream_py_test_tell(PyObject *__pyx_self, PyObject *__pyx_v_stream) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_io_stream_py_test_tell (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stream), __pyx_ptype_8fastwarc_9stream_io_IOStream, 1, "stream", 0))) __PYX_ERR(1, 94, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_4_io_stream_py_test_tell(__pyx_self, ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_stream));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_4_io_stream_py_test_tell(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  size_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_io_stream_py_test_tell", 0);

  /* "fastwarc/stream_io.pyx":100
 *     Test interface for :meth:`IOStream.tell`.
 *     """
 *     return stream.tell()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_stream->__pyx_vtab)->tell(__pyx_v_stream); if (unlikely(__pyx_t_1 == ((size_t)-1L))) __PYX_ERR(1, 100, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":94
 * 
 * 
 * def _io_stream_py_test_tell(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_tell(stream)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":103
 * 
 * 
 * def _io_stream_py_test_seek(IOStream stream, size_t offset):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_seek(stream, offset)
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_7_io_stream_py_test_seek(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_6_io_stream_py_test_seek[] = "\n    io_stream_py_test_seek(stream, offset)\n\n    Test interface for :meth:`IOStream.seek`.\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_7_io_stream_py_test_seek = {"_io_stream_py_test_seek", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8fastwarc_9stream_io_7_io_stream_py_test_seek, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8fastwarc_9stream_io_6_io_stream_py_test_seek};
static PyObject *__pyx_pw_8fastwarc_9stream_io_7_io_stream_py_test_seek(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream = 0;
  size_t __pyx_v_offset;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_io_stream_py_test_seek (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stream,&__pyx_n_s_offset,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stream)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_offset)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_io_stream_py_test_seek", 1, 2, 2, 1); __PYX_ERR(1, 103, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_io_stream_py_test_seek") < 0)) __PYX_ERR(1, 103, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)values[0]);
    __pyx_v_offset = __Pyx_PyInt_As_size_t(values[1]); if (unlikely((__pyx_v_offset == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 103, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_io_stream_py_test_seek", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 103, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stream), __pyx_ptype_8fastwarc_9stream_io_IOStream, 1, "stream", 0))) __PYX_ERR(1, 103, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_6_io_stream_py_test_seek(__pyx_self, __pyx_v_stream, __pyx_v_offset);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_6_io_stream_py_test_seek(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream, size_t __pyx_v_offset) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_io_stream_py_test_seek", 0);

  /* "fastwarc/stream_io.pyx":109
 *     Test interface for :meth:`IOStream.seek`.
 *     """
 *     stream.seek(offset)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_stream->__pyx_vtab)->seek(__pyx_v_stream, __pyx_v_offset); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 109, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":103
 * 
 * 
 * def _io_stream_py_test_seek(IOStream stream, size_t offset):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_seek(stream, offset)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":112
 * 
 * 
 * def _io_stream_py_test_flush(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_flush(stream)
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_9_io_stream_py_test_flush(PyObject *__pyx_self, PyObject *__pyx_v_stream); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_8_io_stream_py_test_flush[] = "\n    io_stream_py_test_flush(stream)\n\n    Test interface for :meth:`IOStream.flush`.\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_9_io_stream_py_test_flush = {"_io_stream_py_test_flush", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_9_io_stream_py_test_flush, METH_O, __pyx_doc_8fastwarc_9stream_io_8_io_stream_py_test_flush};
static PyObject *__pyx_pw_8fastwarc_9stream_io_9_io_stream_py_test_flush(PyObject *__pyx_self, PyObject *__pyx_v_stream) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_io_stream_py_test_flush (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stream), __pyx_ptype_8fastwarc_9stream_io_IOStream, 1, "stream", 0))) __PYX_ERR(1, 112, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_8_io_stream_py_test_flush(__pyx_self, ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_stream));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_8_io_stream_py_test_flush(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_io_stream_py_test_flush", 0);

  /* "fastwarc/stream_io.pyx":118
 *     Test interface for :meth:`IOStream.flush`.
 *     """
 *     stream.flush()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_stream->__pyx_vtab)->flush(__pyx_v_stream); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 118, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":112
 * 
 * 
 * def _io_stream_py_test_flush(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_flush(stream)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_flush", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":121
 * 
 * 
 * def _io_stream_py_test_close(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_close(stream)
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_11_io_stream_py_test_close(PyObject *__pyx_self, PyObject *__pyx_v_stream); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_10_io_stream_py_test_close[] = "\n    io_stream_py_test_close(stream)\n\n    Test interface for :meth:`IOStream.close`.\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_11_io_stream_py_test_close = {"_io_stream_py_test_close", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_11_io_stream_py_test_close, METH_O, __pyx_doc_8fastwarc_9stream_io_10_io_stream_py_test_close};
static PyObject *__pyx_pw_8fastwarc_9stream_io_11_io_stream_py_test_close(PyObject *__pyx_self, PyObject *__pyx_v_stream) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_io_stream_py_test_close (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stream), __pyx_ptype_8fastwarc_9stream_io_IOStream, 1, "stream", 0))) __PYX_ERR(1, 121, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_10_io_stream_py_test_close(__pyx_self, ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_stream));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_10_io_stream_py_test_close(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_io_stream_py_test_close", 0);

  /* "fastwarc/stream_io.pyx":127
 *     Test interface for :meth:`IOStream.close`.
 *     """
 *     stream.close()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_stream->__pyx_vtab)->close(__pyx_v_stream); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 127, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":121
 * 
 * 
 * def _io_stream_py_test_close(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_close(stream)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io._io_stream_py_test_close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":141
 *     :type initial_data: bytes
 *     """
 *     def __init__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_13BytesIOStream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_13BytesIOStream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_13BytesIOStream___init__(((struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_13BytesIOStream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":144
 *         pass
 * 
 *     def __cinit__(self, bytes initial_data=None):             # <<<<<<<<<<<<<<
 *         self.pos = 0
 *         if initial_data is not None:
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_13BytesIOStream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_13BytesIOStream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_initial_data = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_initial_data,0};
    PyObject* values[1] = {0};
    values[0] = ((PyObject*)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_initial_data);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 144, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_initial_data = ((PyObject*)values[0]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 144, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BytesIOStream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_initial_data), (&PyBytes_Type), 1, "initial_data", 1))) __PYX_ERR(1, 144, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_13BytesIOStream_2__cinit__(((struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *)__pyx_v_self), __pyx_v_initial_data);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_13BytesIOStream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, PyObject *__pyx_v_initial_data) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  std::string __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "fastwarc/stream_io.pyx":145
 * 
 *     def __cinit__(self, bytes initial_data=None):
 *         self.pos = 0             # <<<<<<<<<<<<<<
 *         if initial_data is not None:
 *             self.buffer = initial_data
 */
  __pyx_v_self->pos = 0;

  /* "fastwarc/stream_io.pyx":146
 *     def __cinit__(self, bytes initial_data=None):
 *         self.pos = 0
 *         if initial_data is not None:             # <<<<<<<<<<<<<<
 *             self.buffer = initial_data
 * 
 */
  __pyx_t_1 = (__pyx_v_initial_data != ((PyObject*)Py_None));
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "fastwarc/stream_io.pyx":147
 *         self.pos = 0
 *         if initial_data is not None:
 *             self.buffer = initial_data             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t tell(self) except -1:
 */
    __pyx_t_3 = __pyx_convert_string_from_py_std__in_string(__pyx_v_initial_data); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 147, __pyx_L1_error)
    __pyx_v_self->buffer = __pyx_t_3;

    /* "fastwarc/stream_io.pyx":146
 *     def __cinit__(self, bytes initial_data=None):
 *         self.pos = 0
 *         if initial_data is not None:             # <<<<<<<<<<<<<<
 *             self.buffer = initial_data
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":144
 *         pass
 * 
 *     def __cinit__(self, bytes initial_data=None):             # <<<<<<<<<<<<<<
 *         self.pos = 0
 *         if initial_data is not None:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BytesIOStream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":149
 *             self.buffer = initial_data
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_13BytesIOStream_tell(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("tell", 0);

  /* "fastwarc/stream_io.pyx":150
 * 
 *     cdef size_t tell(self) except -1:
 *         if self.pos == strnpos:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         return self.pos
 */
  __pyx_t_1 = ((__pyx_v_self->pos == std::string::npos) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":151
 *     cdef size_t tell(self) except -1:
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         return self.pos
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 151, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 151, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":150
 * 
 *     cdef size_t tell(self) except -1:
 *         if self.pos == strnpos:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         return self.pos
 */
  }

  /* "fastwarc/stream_io.pyx":152
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 *         return self.pos             # <<<<<<<<<<<<<<
 * 
 *     cdef void seek(self, size_t offset) except *:
 */
  __pyx_r = __pyx_v_self->pos;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":149
 *             self.buffer = initial_data
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io.BytesIOStream.tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":154
 *         return self.pos
 * 
 *     cdef void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 */

static void __pyx_f_8fastwarc_9stream_io_13BytesIOStream_seek(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, size_t __pyx_v_offset) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  size_t __pyx_t_3;
  size_t __pyx_t_4;
  size_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("seek", 0);

  /* "fastwarc/stream_io.pyx":155
 * 
 *     cdef void seek(self, size_t offset) except *:
 *         if self.pos == strnpos:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         self.pos = min(self.buffer.size(), offset)
 */
  __pyx_t_1 = ((__pyx_v_self->pos == std::string::npos) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":156
 *     cdef void seek(self, size_t offset) except *:
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         self.pos = min(self.buffer.size(), offset)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 156, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":155
 * 
 *     cdef void seek(self, size_t offset) except *:
 *         if self.pos == strnpos:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         self.pos = min(self.buffer.size(), offset)
 */
  }

  /* "fastwarc/stream_io.pyx":157
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 *         self.pos = min(self.buffer.size(), offset)             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 */
  __pyx_t_3 = __pyx_v_offset;
  __pyx_t_4 = __pyx_v_self->buffer.size();
  if (((__pyx_t_3 < __pyx_t_4) != 0)) {
    __pyx_t_5 = __pyx_t_3;
  } else {
    __pyx_t_5 = __pyx_t_4;
  }
  __pyx_v_self->pos = __pyx_t_5;

  /* "fastwarc/stream_io.pyx":154
 *         return self.pos
 * 
 *     cdef void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io.BytesIOStream.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":159
 *         self.pos = min(self.buffer.size(), offset)
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_13BytesIOStream_read(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("read", 0);

  /* "fastwarc/stream_io.pyx":160
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.pos == strnpos:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos >= self.buffer.size():
 */
  __pyx_t_1 = ((__pyx_v_self->pos == std::string::npos) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":161
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         if self.pos >= self.buffer.size():
 *             return 0
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 161, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 161, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":160
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.pos == strnpos:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos >= self.buffer.size():
 */
  }

  /* "fastwarc/stream_io.pyx":162
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos >= self.buffer.size():             # <<<<<<<<<<<<<<
 *             return 0
 *         if self.pos + size > self.buffer.size():
 */
  __pyx_t_1 = ((__pyx_v_self->pos >= __pyx_v_self->buffer.size()) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":163
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos >= self.buffer.size():
 *             return 0             # <<<<<<<<<<<<<<
 *         if self.pos + size > self.buffer.size():
 *             size = self.buffer.size() - self.pos
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":162
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos >= self.buffer.size():             # <<<<<<<<<<<<<<
 *             return 0
 *         if self.pos + size > self.buffer.size():
 */
  }

  /* "fastwarc/stream_io.pyx":164
 *         if self.pos >= self.buffer.size():
 *             return 0
 *         if self.pos + size > self.buffer.size():             # <<<<<<<<<<<<<<
 *             size = self.buffer.size() - self.pos
 *         memcpy(out, self.buffer.data() + self.pos, size)
 */
  __pyx_t_1 = (((__pyx_v_self->pos + __pyx_v_size) > __pyx_v_self->buffer.size()) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":165
 *             return 0
 *         if self.pos + size > self.buffer.size():
 *             size = self.buffer.size() - self.pos             # <<<<<<<<<<<<<<
 *         memcpy(out, self.buffer.data() + self.pos, size)
 *         self.seek(self.pos + size)
 */
    __pyx_v_size = (__pyx_v_self->buffer.size() - __pyx_v_self->pos);

    /* "fastwarc/stream_io.pyx":164
 *         if self.pos >= self.buffer.size():
 *             return 0
 *         if self.pos + size > self.buffer.size():             # <<<<<<<<<<<<<<
 *             size = self.buffer.size() - self.pos
 *         memcpy(out, self.buffer.data() + self.pos, size)
 */
  }

  /* "fastwarc/stream_io.pyx":166
 *         if self.pos + size > self.buffer.size():
 *             size = self.buffer.size() - self.pos
 *         memcpy(out, self.buffer.data() + self.pos, size)             # <<<<<<<<<<<<<<
 *         self.seek(self.pos + size)
 *         return size
 */
  (void)(memcpy(__pyx_v_out, (__pyx_v_self->buffer.data() + __pyx_v_self->pos), __pyx_v_size));

  /* "fastwarc/stream_io.pyx":167
 *             size = self.buffer.size() - self.pos
 *         memcpy(out, self.buffer.data() + self.pos, size)
 *         self.seek(self.pos + size)             # <<<<<<<<<<<<<<
 *         return size
 * 
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_BytesIOStream *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.seek(((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_self), (__pyx_v_self->pos + __pyx_v_size)); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 167, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":168
 *         memcpy(out, self.buffer.data() + self.pos, size)
 *         self.seek(self.pos + size)
 *         return size             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 */
  __pyx_r = __pyx_v_size;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":159
 *         self.pos = min(self.buffer.size(), offset)
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io.BytesIOStream.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":170
 *         return size
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_13BytesIOStream_write(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write", 0);

  /* "fastwarc/stream_io.pyx":171
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.pos == strnpos:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos + size > self.buffer.size():
 */
  __pyx_t_1 = ((__pyx_v_self->pos == std::string::npos) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":172
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         if self.pos + size > self.buffer.size():
 *             self.buffer.resize(self.pos + size)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 172, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 172, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":171
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.pos == strnpos:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos + size > self.buffer.size():
 */
  }

  /* "fastwarc/stream_io.pyx":173
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos + size > self.buffer.size():             # <<<<<<<<<<<<<<
 *             self.buffer.resize(self.pos + size)
 *         memcpy(self.buffer.data() + self.pos, data, size)
 */
  __pyx_t_1 = (((__pyx_v_self->pos + __pyx_v_size) > __pyx_v_self->buffer.size()) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":174
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos + size > self.buffer.size():
 *             self.buffer.resize(self.pos + size)             # <<<<<<<<<<<<<<
 *         memcpy(self.buffer.data() + self.pos, data, size)
 *         self.pos += size
 */
    try {
      __pyx_v_self->buffer.resize((__pyx_v_self->pos + __pyx_v_size));
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 174, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":173
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 *         if self.pos + size > self.buffer.size():             # <<<<<<<<<<<<<<
 *             self.buffer.resize(self.pos + size)
 *         memcpy(self.buffer.data() + self.pos, data, size)
 */
  }

  /* "fastwarc/stream_io.pyx":175
 *         if self.pos + size > self.buffer.size():
 *             self.buffer.resize(self.pos + size)
 *         memcpy(self.buffer.data() + self.pos, data, size)             # <<<<<<<<<<<<<<
 *         self.pos += size
 *         return size
 */
  (void)(memcpy((__pyx_v_self->buffer.data() + __pyx_v_self->pos), __pyx_v_data, __pyx_v_size));

  /* "fastwarc/stream_io.pyx":176
 *             self.buffer.resize(self.pos + size)
 *         memcpy(self.buffer.data() + self.pos, data, size)
 *         self.pos += size             # <<<<<<<<<<<<<<
 *         return size
 * 
 */
  __pyx_v_self->pos = (__pyx_v_self->pos + __pyx_v_size);

  /* "fastwarc/stream_io.pyx":177
 *         memcpy(self.buffer.data() + self.pos, data, size)
 *         self.pos += size
 *         return size             # <<<<<<<<<<<<<<
 * 
 *     cdef void close(self) except *:
 */
  __pyx_r = __pyx_v_size;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":170
 *         return size
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io.BytesIOStream.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":179
 *         return size
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         self.buffer.clear()
 *         self.pos = strnpos
 */

static void __pyx_f_8fastwarc_9stream_io_13BytesIOStream_close(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close", 0);

  /* "fastwarc/stream_io.pyx":180
 * 
 *     cdef void close(self) except *:
 *         self.buffer.clear()             # <<<<<<<<<<<<<<
 *         self.pos = strnpos
 * 
 */
  __pyx_v_self->buffer.clear();

  /* "fastwarc/stream_io.pyx":181
 *     cdef void close(self) except *:
 *         self.buffer.clear()
 *         self.pos = strnpos             # <<<<<<<<<<<<<<
 * 
 *     cdef inline string getvalue(self):
 */
  __pyx_v_self->pos = std::string::npos;

  /* "fastwarc/stream_io.pyx":179
 *         return size
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         self.buffer.clear()
 *         self.pos = strnpos
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":183
 *         self.pos = strnpos
 * 
 *     cdef inline string getvalue(self):             # <<<<<<<<<<<<<<
 *         return self.buffer
 * 
 */

static std::string __pyx_f_8fastwarc_9stream_io_13BytesIOStream_getvalue(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *__pyx_v_self) {
  std::string __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getvalue", 0);

  /* "fastwarc/stream_io.pyx":184
 * 
 *     cdef inline string getvalue(self):
 *         return self.buffer             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_self->buffer;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":183
 *         self.pos = strnpos
 * 
 *     cdef inline string getvalue(self):             # <<<<<<<<<<<<<<
 *         return self.buffer
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":201
 *     """
 * 
 *     def __init__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_10FileStream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_10FileStream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_10FileStream___init__(((struct __pyx_obj_8fastwarc_9stream_io_FileStream *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_10FileStream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":204
 *         pass
 * 
 *     def __cinit__(self, str filename=None, str mode='rb'):             # <<<<<<<<<<<<<<
 *         self.fp = NULL
 *         if filename:
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_10FileStream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_10FileStream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_filename = 0;
  PyObject *__pyx_v_mode = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_mode,0};
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject*)Py_None);
    values[1] = ((PyObject*)__pyx_n_u_rb);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filename);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 204, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_filename = ((PyObject*)values[0]);
    __pyx_v_mode = ((PyObject*)values[1]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 204, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.FileStream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_filename), (&PyUnicode_Type), 1, "filename", 1))) __PYX_ERR(1, 204, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mode), (&PyUnicode_Type), 1, "mode", 1))) __PYX_ERR(1, 204, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_10FileStream_2__cinit__(((struct __pyx_obj_8fastwarc_9stream_io_FileStream *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_10FileStream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char const *__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  struct __pyx_opt_args_8fastwarc_9stream_io_10FileStream_open __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "fastwarc/stream_io.pyx":205
 * 
 *     def __cinit__(self, str filename=None, str mode='rb'):
 *         self.fp = NULL             # <<<<<<<<<<<<<<
 *         if filename:
 *             self.open(filename.encode(), mode.encode())
 */
  __pyx_v_self->fp = NULL;

  /* "fastwarc/stream_io.pyx":206
 *     def __cinit__(self, str filename=None, str mode='rb'):
 *         self.fp = NULL
 *         if filename:             # <<<<<<<<<<<<<<
 *             self.open(filename.encode(), mode.encode())
 * 
 */
  __pyx_t_1 = (__pyx_v_filename != Py_None)&&(__Pyx_PyUnicode_IS_TRUE(__pyx_v_filename) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":207
 *         self.fp = NULL
 *         if filename:
 *             self.open(filename.encode(), mode.encode())             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    if (unlikely(__pyx_v_filename == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "encode");
      __PYX_ERR(1, 207, __pyx_L1_error)
    }
    __pyx_t_2 = PyUnicode_AsEncodedString(__pyx_v_filename, NULL, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 207, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyBytes_AsString(__pyx_t_2); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(1, 207, __pyx_L1_error)
    if (unlikely(__pyx_v_mode == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "encode");
      __PYX_ERR(1, 207, __pyx_L1_error)
    }
    __pyx_t_4 = PyUnicode_AsEncodedString(__pyx_v_mode, NULL, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 207, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_t_4); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(1, 207, __pyx_L1_error)
    __pyx_t_6.__pyx_n = 1;
    __pyx_t_6.mode = __pyx_t_5;
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_FileStream *)__pyx_v_self->__pyx_base.__pyx_vtab)->open(__pyx_v_self, __pyx_t_3, &__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 207, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "fastwarc/stream_io.pyx":206
 *     def __cinit__(self, str filename=None, str mode='rb'):
 *         self.fp = NULL
 *         if filename:             # <<<<<<<<<<<<<<
 *             self.open(filename.encode(), mode.encode())
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":204
 *         pass
 * 
 *     def __cinit__(self, str filename=None, str mode='rb'):             # <<<<<<<<<<<<<<
 *         self.fp = NULL
 *         if filename:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.FileStream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":209
 *             self.open(filename.encode(), mode.encode())
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

/* Python wrapper */
static void __pyx_pw_8fastwarc_9stream_io_10FileStream_5__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_8fastwarc_9stream_io_10FileStream_5__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_8fastwarc_9stream_io_10FileStream_4__dealloc__(((struct __pyx_obj_8fastwarc_9stream_io_FileStream *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_8fastwarc_9stream_io_10FileStream_4__dealloc__(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "fastwarc/stream_io.pyx":210
 * 
 *     def __dealloc__(self):
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     cdef void open(self, char* path, char* mode=b'rb') except *:
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_FileStream *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.close(((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_self)); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 210, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":209
 *             self.open(filename.encode(), mode.encode())
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("fastwarc.stream_io.FileStream.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":212
 *         self.close()
 * 
 *     cdef void open(self, char* path, char* mode=b'rb') except *:             # <<<<<<<<<<<<<<
 *         if self.fp != NULL:
 *             self.close()
 */

static void __pyx_f_8fastwarc_9stream_io_10FileStream_open(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, char *__pyx_v_path, struct __pyx_opt_args_8fastwarc_9stream_io_10FileStream_open *__pyx_optional_args) {
  char *__pyx_v_mode = ((char *)((char *)"rb"));
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("open", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_mode = __pyx_optional_args->mode;
    }
  }

  /* "fastwarc/stream_io.pyx":213
 * 
 *     cdef void open(self, char* path, char* mode=b'rb') except *:
 *         if self.fp != NULL:             # <<<<<<<<<<<<<<
 *             self.close()
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->fp != NULL) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":214
 *     cdef void open(self, char* path, char* mode=b'rb') except *:
 *         if self.fp != NULL:
 *             self.close()             # <<<<<<<<<<<<<<
 * 
 *         self.fp = fopen(path, mode)
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_FileStream *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.close(((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_self)); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 214, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":213
 * 
 *     cdef void open(self, char* path, char* mode=b'rb') except *:
 *         if self.fp != NULL:             # <<<<<<<<<<<<<<
 *             self.close()
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":216
 *             self.close()
 * 
 *         self.fp = fopen(path, mode)             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise StreamError(strerror(errno).decode())
 */
  __pyx_v_self->fp = fopen(__pyx_v_path, __pyx_v_mode);

  /* "fastwarc/stream_io.pyx":217
 * 
 *         self.fp = fopen(path, mode)
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise StreamError(strerror(errno).decode())
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":218
 *         self.fp = fopen(path, mode)
 *         if self.fp == NULL:
 *             raise StreamError(strerror(errno).decode())             # <<<<<<<<<<<<<<
 * 
 *     cdef void seek(self, size_t offset) except *:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 218, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = std::strerror(errno);
    __pyx_t_5 = __Pyx_decode_c_string(__pyx_t_4, 0, strlen(__pyx_t_4), NULL, NULL, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 218, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 218, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 218, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":217
 * 
 *         self.fp = fopen(path, mode)
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise StreamError(strerror(errno).decode())
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":212
 *         self.close()
 * 
 *     cdef void open(self, char* path, char* mode=b'rb') except *:             # <<<<<<<<<<<<<<
 *         if self.fp != NULL:
 *             self.close()
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("fastwarc.stream_io.FileStream.open", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":220
 *             raise StreamError(strerror(errno).decode())
 * 
 *     cdef void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

static void __pyx_f_8fastwarc_9stream_io_10FileStream_seek(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, size_t __pyx_v_offset) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("seek", 0);

  /* "fastwarc/stream_io.pyx":221
 * 
 *     cdef void seek(self, size_t offset) except *:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         fseek(self.fp, <unsigned long>offset, SEEK_SET)
 */
  __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":222
 *     cdef void seek(self, size_t offset) except *:
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         fseek(self.fp, <unsigned long>offset, SEEK_SET)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 222, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":221
 * 
 *     cdef void seek(self, size_t offset) except *:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         fseek(self.fp, <unsigned long>offset, SEEK_SET)
 */
  }

  /* "fastwarc/stream_io.pyx":223
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 *         fseek(self.fp, <unsigned long>offset, SEEK_SET)             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t tell(self) except -1:
 */
  (void)(fseek(__pyx_v_self->fp, ((unsigned long)__pyx_v_offset), SEEK_SET));

  /* "fastwarc/stream_io.pyx":220
 *             raise StreamError(strerror(errno).decode())
 * 
 *     cdef void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io.FileStream.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":225
 *         fseek(self.fp, <unsigned long>offset, SEEK_SET)
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_10FileStream_tell(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("tell", 0);

  /* "fastwarc/stream_io.pyx":226
 * 
 *     cdef size_t tell(self) except -1:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         return ftell(self.fp)
 */
  __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":227
 *     cdef size_t tell(self) except -1:
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         return ftell(self.fp)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 227, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":226
 * 
 *     cdef size_t tell(self) except -1:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         return ftell(self.fp)
 */
  }

  /* "fastwarc/stream_io.pyx":228
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 *         return ftell(self.fp)             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 */
  __pyx_r = ftell(__pyx_v_self->fp);
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":225
 *         fseek(self.fp, <unsigned long>offset, SEEK_SET)
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io.FileStream.tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":230
 *         return ftell(self.fp)
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_10FileStream_read(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size) {
  size_t __pyx_v_bytes_read;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("read", 0);

  /* "fastwarc/stream_io.pyx":231
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t bytes_read
 */
  __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":232
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         cdef size_t bytes_read
 *         with nogil:
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 232, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 232, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":231
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t bytes_read
 */
  }

  /* "fastwarc/stream_io.pyx":234
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t bytes_read
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bytes_read = fread(out, sizeof(char), size, self.fp)
 *             if bytes_read < size and ferror(self.fp):
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "fastwarc/stream_io.pyx":235
 *         cdef size_t bytes_read
 *         with nogil:
 *             bytes_read = fread(out, sizeof(char), size, self.fp)             # <<<<<<<<<<<<<<
 *             if bytes_read < size and ferror(self.fp):
 *                 with gil:
 */
        __pyx_v_bytes_read = fread(__pyx_v_out, (sizeof(char)), __pyx_v_size, __pyx_v_self->fp);

        /* "fastwarc/stream_io.pyx":236
 *         with nogil:
 *             bytes_read = fread(out, sizeof(char), size, self.fp)
 *             if bytes_read < size and ferror(self.fp):             # <<<<<<<<<<<<<<
 *                 with gil:
 *                     raise StreamError('Error reading file')
 */
        __pyx_t_3 = ((__pyx_v_bytes_read < __pyx_v_size) != 0);
        if (__pyx_t_3) {
        } else {
          __pyx_t_1 = __pyx_t_3;
          goto __pyx_L8_bool_binop_done;
        }
        __pyx_t_3 = (ferror(__pyx_v_self->fp) != 0);
        __pyx_t_1 = __pyx_t_3;
        __pyx_L8_bool_binop_done:;
        if (__pyx_t_1) {

          /* "fastwarc/stream_io.pyx":237
 *             bytes_read = fread(out, sizeof(char), size, self.fp)
 *             if bytes_read < size and ferror(self.fp):
 *                 with gil:             # <<<<<<<<<<<<<<
 *                     raise StreamError('Error reading file')
 *             return bytes_read
 */
          {
              #ifdef WITH_THREAD
              PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
              #endif
              /*try:*/ {

                /* "fastwarc/stream_io.pyx":238
 *             if bytes_read < size and ferror(self.fp):
 *                 with gil:
 *                     raise StreamError('Error reading file')             # <<<<<<<<<<<<<<
 *             return bytes_read
 * 
 */
                __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 238, __pyx_L11_error)
                __Pyx_GOTREF(__pyx_t_4);
                __pyx_t_5 = NULL;
                if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
                  __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
                  if (likely(__pyx_t_5)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
                    __Pyx_INCREF(__pyx_t_5);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_4, function);
                  }
                }
                __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_kp_u_Error_reading_file) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_Error_reading_file);
                __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 238, __pyx_L11_error)
                __Pyx_GOTREF(__pyx_t_2);
                __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                __Pyx_Raise(__pyx_t_2, 0, 0, 0);
                __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
                __PYX_ERR(1, 238, __pyx_L11_error)
              }

              /* "fastwarc/stream_io.pyx":237
 *             bytes_read = fread(out, sizeof(char), size, self.fp)
 *             if bytes_read < size and ferror(self.fp):
 *                 with gil:             # <<<<<<<<<<<<<<
 *                     raise StreamError('Error reading file')
 *             return bytes_read
 */
              /*finally:*/ {
                __pyx_L11_error: {
                  #ifdef WITH_THREAD
                  __Pyx_PyGILState_Release(__pyx_gilstate_save);
                  #endif
                  goto __pyx_L5_error;
                }
              }
          }

          /* "fastwarc/stream_io.pyx":236
 *         with nogil:
 *             bytes_read = fread(out, sizeof(char), size, self.fp)
 *             if bytes_read < size and ferror(self.fp):             # <<<<<<<<<<<<<<
 *                 with gil:
 *                     raise StreamError('Error reading file')
 */
        }

        /* "fastwarc/stream_io.pyx":239
 *                 with gil:
 *                     raise StreamError('Error reading file')
 *             return bytes_read             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 */
        __pyx_r = __pyx_v_bytes_read;
        goto __pyx_L4_return;
      }

      /* "fastwarc/stream_io.pyx":234
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t bytes_read
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bytes_read = fread(out, sizeof(char), size, self.fp)
 *             if bytes_read < size and ferror(self.fp):
 */
      /*finally:*/ {
        __pyx_L4_return: {
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L0;
        }
        __pyx_L5_error: {
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L1_error;
        }
      }
  }

  /* "fastwarc/stream_io.pyx":230
 *         return ftell(self.fp)
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("fastwarc.stream_io.FileStream.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":241
 *             return bytes_read
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_10FileStream_write(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size) {
  size_t __pyx_v_w;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write", 0);

  /* "fastwarc/stream_io.pyx":242
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t w = fwrite(data, sizeof(char), size, self.fp)
 */
  __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":243
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         cdef size_t w = fwrite(data, sizeof(char), size, self.fp)
 *         if ferror(self.fp):
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 243, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 243, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":242
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t w = fwrite(data, sizeof(char), size, self.fp)
 */
  }

  /* "fastwarc/stream_io.pyx":244
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t w = fwrite(data, sizeof(char), size, self.fp)             # <<<<<<<<<<<<<<
 *         if ferror(self.fp):
 *             raise StreamError('Error writing file')
 */
  __pyx_v_w = fwrite(__pyx_v_data, (sizeof(char)), __pyx_v_size, __pyx_v_self->fp);

  /* "fastwarc/stream_io.pyx":245
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t w = fwrite(data, sizeof(char), size, self.fp)
 *         if ferror(self.fp):             # <<<<<<<<<<<<<<
 *             raise StreamError('Error writing file')
 *         return w
 */
  __pyx_t_1 = (ferror(__pyx_v_self->fp) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":246
 *         cdef size_t w = fwrite(data, sizeof(char), size, self.fp)
 *         if ferror(self.fp):
 *             raise StreamError('Error writing file')             # <<<<<<<<<<<<<<
 *         return w
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 246, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_Error_writing_file) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_Error_writing_file);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 246, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 246, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":245
 *             raise ValueError('Trying I/O on closed file.')
 *         cdef size_t w = fwrite(data, sizeof(char), size, self.fp)
 *         if ferror(self.fp):             # <<<<<<<<<<<<<<
 *             raise StreamError('Error writing file')
 *         return w
 */
  }

  /* "fastwarc/stream_io.pyx":247
 *         if ferror(self.fp):
 *             raise StreamError('Error writing file')
 *         return w             # <<<<<<<<<<<<<<
 * 
 *     cdef void flush(self) except *:
 */
  __pyx_r = __pyx_v_w;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":241
 *             return bytes_read
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.FileStream.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":249
 *         return w
 * 
 *     cdef void flush(self) except *:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

static void __pyx_f_8fastwarc_9stream_io_10FileStream_flush(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("flush", 0);

  /* "fastwarc/stream_io.pyx":250
 * 
 *     cdef void flush(self) except *:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         fflush(self.fp)
 */
  __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":251
 *     cdef void flush(self) except *:
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         fflush(self.fp)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 251, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":250
 * 
 *     cdef void flush(self) except *:
 *         if self.fp == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError('Trying I/O on closed file.')
 *         fflush(self.fp)
 */
  }

  /* "fastwarc/stream_io.pyx":252
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 *         fflush(self.fp)             # <<<<<<<<<<<<<<
 * 
 *     cdef void close(self) except *:
 */
  (void)(fflush(__pyx_v_self->fp));

  /* "fastwarc/stream_io.pyx":249
 *         return w
 * 
 *     cdef void flush(self) except *:             # <<<<<<<<<<<<<<
 *         if self.fp == NULL:
 *             raise ValueError('Trying I/O on closed file.')
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io.FileStream.flush", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":254
 *         fflush(self.fp)
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         if self.fp != NULL:
 *             fclose(self.fp)
 */

static void __pyx_f_8fastwarc_9stream_io_10FileStream_close(struct __pyx_obj_8fastwarc_9stream_io_FileStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("close", 0);

  /* "fastwarc/stream_io.pyx":255
 * 
 *     cdef void close(self) except *:
 *         if self.fp != NULL:             # <<<<<<<<<<<<<<
 *             fclose(self.fp)
 *             self.fp = NULL
 */
  __pyx_t_1 = ((__pyx_v_self->fp != NULL) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":256
 *     cdef void close(self) except *:
 *         if self.fp != NULL:
 *             fclose(self.fp)             # <<<<<<<<<<<<<<
 *             self.fp = NULL
 * 
 */
    (void)(fclose(__pyx_v_self->fp));

    /* "fastwarc/stream_io.pyx":257
 *         if self.fp != NULL:
 *             fclose(self.fp)
 *             self.fp = NULL             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_self->fp = NULL;

    /* "fastwarc/stream_io.pyx":255
 * 
 *     cdef void close(self) except *:
 *         if self.fp != NULL:             # <<<<<<<<<<<<<<
 *             fclose(self.fp)
 *             self.fp = NULL
 */
  }

  /* "fastwarc/stream_io.pyx":254
 *         fflush(self.fp)
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         if self.fp != NULL:
 *             fclose(self.fp)
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":270
 *     """
 * 
 *     def __init__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_21PythonIOStreamAdapter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_21PythonIOStreamAdapter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_21PythonIOStreamAdapter___init__(((struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_21PythonIOStreamAdapter___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":273
 *         pass
 * 
 *     def __cinit__(self, py_stream):             # <<<<<<<<<<<<<<
 *         self.py_stream = py_stream
 * 
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_21PythonIOStreamAdapter_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_21PythonIOStreamAdapter_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_py_stream = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_py_stream,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_py_stream)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 273, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_py_stream = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 273, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.PythonIOStreamAdapter.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_21PythonIOStreamAdapter_2__cinit__(((struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *)__pyx_v_self), __pyx_v_py_stream);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_21PythonIOStreamAdapter_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, PyObject *__pyx_v_py_stream) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "fastwarc/stream_io.pyx":274
 * 
 *     def __cinit__(self, py_stream):
 *         self.py_stream = py_stream             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_INCREF(__pyx_v_py_stream);
  __Pyx_GIVEREF(__pyx_v_py_stream);
  __Pyx_GOTREF(__pyx_v_self->py_stream);
  __Pyx_DECREF(__pyx_v_self->py_stream);
  __pyx_v_self->py_stream = __pyx_v_py_stream;

  /* "fastwarc/stream_io.pyx":273
 *         pass
 * 
 *     def __cinit__(self, py_stream):             # <<<<<<<<<<<<<<
 *         self.py_stream = py_stream
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":277
 * 
 * 
 * cpdef IOStream wrap_stream(raw_stream):             # <<<<<<<<<<<<<<
 *     """
 *     wrap_stream(raw_stream)
 */

static PyObject *__pyx_pw_8fastwarc_9stream_io_13wrap_stream(PyObject *__pyx_self, PyObject *__pyx_v_raw_stream); /*proto*/
static struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_f_8fastwarc_9stream_io_wrap_stream(PyObject *__pyx_v_raw_stream, CYTHON_UNUSED int __pyx_skip_dispatch) {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  Py_UCS4 __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("wrap_stream", 0);

  /* "fastwarc/stream_io.pyx":288
 *     :rtype: IOStream
 *     """
 *     if isinstance(raw_stream, IOStream):             # <<<<<<<<<<<<<<
 *         return raw_stream
 *     elif isinstance(raw_stream, object) and hasattr(raw_stream, 'read'):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_raw_stream, __pyx_ptype_8fastwarc_9stream_io_IOStream); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "fastwarc/stream_io.pyx":289
 *     """
 *     if isinstance(raw_stream, IOStream):
 *         return raw_stream             # <<<<<<<<<<<<<<
 *     elif isinstance(raw_stream, object) and hasattr(raw_stream, 'read'):
 *         return PythonIOStreamAdapter.__new__(PythonIOStreamAdapter, raw_stream)
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    if (!(likely(((__pyx_v_raw_stream) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_raw_stream, __pyx_ptype_8fastwarc_9stream_io_IOStream))))) __PYX_ERR(1, 289, __pyx_L1_error)
    __Pyx_INCREF(__pyx_v_raw_stream);
    __pyx_r = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_raw_stream);
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":288
 *     :rtype: IOStream
 *     """
 *     if isinstance(raw_stream, IOStream):             # <<<<<<<<<<<<<<
 *         return raw_stream
 *     elif isinstance(raw_stream, object) and hasattr(raw_stream, 'read'):
 */
  }

  /* "fastwarc/stream_io.pyx":290
 *     if isinstance(raw_stream, IOStream):
 *         return raw_stream
 *     elif isinstance(raw_stream, object) and hasattr(raw_stream, 'read'):             # <<<<<<<<<<<<<<
 *         return PythonIOStreamAdapter.__new__(PythonIOStreamAdapter, raw_stream)
 *     else:
 */
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_raw_stream, __pyx_builtin_object); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(1, 290, __pyx_L1_error)
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_HasAttr(__pyx_v_raw_stream, __pyx_n_u_read); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 290, __pyx_L1_error)
  __pyx_t_1 = (__pyx_t_3 != 0);
  __pyx_t_2 = __pyx_t_1;
  __pyx_L4_bool_binop_done:;
  if (likely(__pyx_t_2)) {

    /* "fastwarc/stream_io.pyx":291
 *         return raw_stream
 *     elif isinstance(raw_stream, object) and hasattr(raw_stream, 'read'):
 *         return PythonIOStreamAdapter.__new__(PythonIOStreamAdapter, raw_stream)             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError(f"Object of type '{type(raw_stream).__name__}' is not a valid stream.")
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 291, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_raw_stream);
    __Pyx_GIVEREF(__pyx_v_raw_stream);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_raw_stream);
    __pyx_t_5 = ((PyObject *)__pyx_tp_new_8fastwarc_9stream_io_PythonIOStreamAdapter(((PyTypeObject *)__pyx_ptype_8fastwarc_9stream_io_PythonIOStreamAdapter), __pyx_t_4, NULL)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 291, __pyx_L1_error)
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(__Pyx_TypeTest(((PyObject *)__pyx_t_5), __pyx_ptype_8fastwarc_9stream_io_IOStream)))) __PYX_ERR(1, 291, __pyx_L1_error)
    __pyx_r = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_t_5);
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":290
 *     if isinstance(raw_stream, IOStream):
 *         return raw_stream
 *     elif isinstance(raw_stream, object) and hasattr(raw_stream, 'read'):             # <<<<<<<<<<<<<<
 *         return PythonIOStreamAdapter.__new__(PythonIOStreamAdapter, raw_stream)
 *     else:
 */
  }

  /* "fastwarc/stream_io.pyx":293
 *         return PythonIOStreamAdapter.__new__(PythonIOStreamAdapter, raw_stream)
 *     else:
 *         raise ValueError(f"Object of type '{type(raw_stream).__name__}' is not a valid stream.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = 0;
    __pyx_t_7 = 127;
    __Pyx_INCREF(__pyx_kp_u_Object_of_type);
    __pyx_t_6 += 16;
    __Pyx_GIVEREF(__pyx_kp_u_Object_of_type);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_Object_of_type);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_raw_stream)), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) > __pyx_t_7) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) : __pyx_t_7;
    __pyx_t_6 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_INCREF(__pyx_kp_u_is_not_a_valid_stream);
    __pyx_t_6 += 24;
    __Pyx_GIVEREF(__pyx_kp_u_is_not_a_valid_stream);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_is_not_a_valid_stream);
    __pyx_t_8 = __Pyx_PyUnicode_Join(__pyx_t_5, 3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(1, 293, __pyx_L1_error)
  }

  /* "fastwarc/stream_io.pyx":277
 * 
 * 
 * cpdef IOStream wrap_stream(raw_stream):             # <<<<<<<<<<<<<<
 *     """
 *     wrap_stream(raw_stream)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("fastwarc.stream_io.wrap_stream", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_13wrap_stream(PyObject *__pyx_self, PyObject *__pyx_v_raw_stream); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_12wrap_stream[] = "\n    wrap_stream(raw_stream)\n    \n    Wrap ``raw_stream`` into a :class:`PythonIOStreamAdapter` if it is a Python object or\n    return ``raw_stream`` unmodified if it is a :class:`IOStream` already.\n    \n    :param raw_stream: stream to wrap\n    :return: wrapped stream\n    :rtype: IOStream\n    ";
static PyObject *__pyx_pw_8fastwarc_9stream_io_13wrap_stream(PyObject *__pyx_self, PyObject *__pyx_v_raw_stream) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("wrap_stream (wrapper)", 0);
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_12wrap_stream(__pyx_self, ((PyObject *)__pyx_v_raw_stream));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_12wrap_stream(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_raw_stream) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("wrap_stream", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_8fastwarc_9stream_io_wrap_stream(__pyx_v_raw_stream, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 277, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("fastwarc.stream_io.wrap_stream", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":300
 *     """Base class for compressed :class:`IOStream` types."""
 * 
 *     cdef size_t begin_member(self):             # <<<<<<<<<<<<<<
 *         """Begin compression member/frame (if not already started)."""
 *         return 0
 */

static size_t __pyx_f_8fastwarc_9stream_io_17CompressingStream_begin_member(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("begin_member", 0);

  /* "fastwarc/stream_io.pyx":302
 *     cdef size_t begin_member(self):
 *         """Begin compression member/frame (if not already started)."""
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t end_member(self):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":300
 *     """Base class for compressed :class:`IOStream` types."""
 * 
 *     cdef size_t begin_member(self):             # <<<<<<<<<<<<<<
 *         """Begin compression member/frame (if not already started)."""
 *         return 0
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":304
 *         return 0
 * 
 *     cdef size_t end_member(self):             # <<<<<<<<<<<<<<
 *         """End compression member/frame (if one has been started)."""
 *         return 0
 */

static size_t __pyx_f_8fastwarc_9stream_io_17CompressingStream_end_member(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("end_member", 0);

  /* "fastwarc/stream_io.pyx":306
 *     cdef size_t end_member(self):
 *         """End compression member/frame (if one has been started)."""
 *         return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":304
 *         return 0
 * 
 *     cdef size_t end_member(self):             # <<<<<<<<<<<<<<
 *         """End compression member/frame (if one has been started)."""
 *         return 0
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":324
 *     """
 * 
 *     def __init__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_10GZipStream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_10GZipStream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_10GZipStream___init__(((struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_10GZipStream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":327
 *         pass
 * 
 *     def __cinit__(self, raw_stream, compression_level=Z_BEST_COMPRESSION, bint zlib=False):             # <<<<<<<<<<<<<<
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.member_started = False
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_10GZipStream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_10GZipStream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_raw_stream = 0;
  PyObject *__pyx_v_compression_level = 0;
  int __pyx_v_zlib;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_raw_stream,&__pyx_n_s_compression_level,&__pyx_n_s_zlib,0};
    PyObject* values[3] = {0,0,0};
    values[1] = __pyx_k__2;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raw_stream)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_compression_level);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zlib);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 327, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_raw_stream = values[0];
    __pyx_v_compression_level = values[1];
    if (values[2]) {
      __pyx_v_zlib = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_zlib == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 327, __pyx_L3_error)
    } else {
      __pyx_v_zlib = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 327, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.GZipStream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_10GZipStream_2__cinit__(((struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)__pyx_v_self), __pyx_v_raw_stream, __pyx_v_compression_level, __pyx_v_zlib);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_10GZipStream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, PyObject *__pyx_v_raw_stream, PyObject *__pyx_v_compression_level, int __pyx_v_zlib) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  size_t __pyx_t_2;
  int __pyx_t_3;
  long __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "fastwarc/stream_io.pyx":328
 * 
 *     def __cinit__(self, raw_stream, compression_level=Z_BEST_COMPRESSION, bint zlib=False):
 *         self.raw_stream = wrap_stream(raw_stream)             # <<<<<<<<<<<<<<
 *         self.member_started = False
 *         self.working_buf_filled = 0u
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_8fastwarc_9stream_io_wrap_stream(__pyx_v_raw_stream, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 328, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->raw_stream);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->raw_stream));
  __pyx_v_self->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":329
 *     def __cinit__(self, raw_stream, compression_level=Z_BEST_COMPRESSION, bint zlib=False):
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.member_started = False             # <<<<<<<<<<<<<<
 *         self.working_buf_filled = 0u
 *         self.stream_state = CompressingStreamState.UNINIT
 */
  __pyx_v_self->member_started = 0;

  /* "fastwarc/stream_io.pyx":330
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.member_started = False
 *         self.working_buf_filled = 0u             # <<<<<<<<<<<<<<
 *         self.stream_state = CompressingStreamState.UNINIT
 *         self.stream_pos = self.raw_stream.tell()
 */
  __pyx_v_self->working_buf_filled = 0U;

  /* "fastwarc/stream_io.pyx":331
 *         self.member_started = False
 *         self.working_buf_filled = 0u
 *         self.stream_state = CompressingStreamState.UNINIT             # <<<<<<<<<<<<<<
 *         self.stream_pos = self.raw_stream.tell()
 *         self.compression_level = compression_level
 */
  __pyx_v_self->stream_state = UNINIT;

  /* "fastwarc/stream_io.pyx":332
 *         self.working_buf_filled = 0u
 *         self.stream_state = CompressingStreamState.UNINIT
 *         self.stream_pos = self.raw_stream.tell()             # <<<<<<<<<<<<<<
 *         self.compression_level = compression_level
 *         self.window_bits = MAX_WBITS if zlib else 16 + MAX_WBITS
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->tell(__pyx_v_self->raw_stream); if (unlikely(__pyx_t_2 == ((size_t)-1L))) __PYX_ERR(1, 332, __pyx_L1_error)
  __pyx_v_self->stream_pos = __pyx_t_2;

  /* "fastwarc/stream_io.pyx":333
 *         self.stream_state = CompressingStreamState.UNINIT
 *         self.stream_pos = self.raw_stream.tell()
 *         self.compression_level = compression_level             # <<<<<<<<<<<<<<
 *         self.window_bits = MAX_WBITS if zlib else 16 + MAX_WBITS
 * 
 */
  __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_compression_level); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 333, __pyx_L1_error)
  __pyx_v_self->compression_level = __pyx_t_3;

  /* "fastwarc/stream_io.pyx":334
 *         self.stream_pos = self.raw_stream.tell()
 *         self.compression_level = compression_level
 *         self.window_bits = MAX_WBITS if zlib else 16 + MAX_WBITS             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  if ((__pyx_v_zlib != 0)) {
    __pyx_t_4 = MAX_WBITS;
  } else {
    __pyx_t_4 = (16 + MAX_WBITS);
  }
  __pyx_v_self->window_bits = __pyx_t_4;

  /* "fastwarc/stream_io.pyx":327
 *         pass
 * 
 *     def __cinit__(self, raw_stream, compression_level=Z_BEST_COMPRESSION, bint zlib=False):             # <<<<<<<<<<<<<<
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.member_started = False
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("fastwarc.stream_io.GZipStream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":336
 *         self.window_bits = MAX_WBITS if zlib else 16 + MAX_WBITS
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

/* Python wrapper */
static void __pyx_pw_8fastwarc_9stream_io_10GZipStream_5__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_8fastwarc_9stream_io_10GZipStream_5__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_8fastwarc_9stream_io_10GZipStream_4__dealloc__(((struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_8fastwarc_9stream_io_10GZipStream_4__dealloc__(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "fastwarc/stream_io.pyx":337
 * 
 *     def __dealloc__(self):
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t tell(self) except -1:
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.close(((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_self)); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 337, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":336
 *         self.window_bits = MAX_WBITS if zlib else 16 + MAX_WBITS
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("fastwarc.stream_io.GZipStream.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":339
 *         self.close()
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         return self.stream_pos
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_tell(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("tell", 0);

  /* "fastwarc/stream_io.pyx":340
 * 
 *     cdef size_t tell(self) except -1:
 *         return self.stream_pos             # <<<<<<<<<<<<<<
 * 
 *     cdef void _init_z_stream(self, bint deflate) nogil:
 */
  __pyx_r = __pyx_v_self->stream_pos;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":339
 *         self.close()
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         return self.stream_pos
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":342
 *         return self.stream_pos
 * 
 *     cdef void _init_z_stream(self, bint deflate) nogil:             # <<<<<<<<<<<<<<
 *         """
 *         Reset internal state and initialize ``z_stream``.
 */

static void __pyx_f_8fastwarc_9stream_io_10GZipStream__init_z_stream(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, int __pyx_v_deflate) {
  int __pyx_t_1;

  /* "fastwarc/stream_io.pyx":349
 *         """
 * 
 *         if self.stream_state != CompressingStreamState.UNINIT:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->stream_state != UNINIT) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":350
 * 
 *         if self.stream_state != CompressingStreamState.UNINIT:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         self.zst.opaque = Z_NULL
 */
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":349
 *         """
 * 
 *         if self.stream_state != CompressingStreamState.UNINIT:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":352
 *             return
 * 
 *         self.zst.opaque = Z_NULL             # <<<<<<<<<<<<<<
 *         self.zst.zalloc = Z_NULL
 *         self.zst.zfree = Z_NULL
 */
  __pyx_v_self->zst.opaque = Z_NULL;

  /* "fastwarc/stream_io.pyx":353
 * 
 *         self.zst.opaque = Z_NULL
 *         self.zst.zalloc = Z_NULL             # <<<<<<<<<<<<<<
 *         self.zst.zfree = Z_NULL
 *         self.zst.next_in = NULL
 */
  __pyx_v_self->zst.zalloc = Z_NULL;

  /* "fastwarc/stream_io.pyx":354
 *         self.zst.opaque = Z_NULL
 *         self.zst.zalloc = Z_NULL
 *         self.zst.zfree = Z_NULL             # <<<<<<<<<<<<<<
 *         self.zst.next_in = NULL
 *         self.zst.next_out = NULL
 */
  __pyx_v_self->zst.zfree = Z_NULL;

  /* "fastwarc/stream_io.pyx":355
 *         self.zst.zalloc = Z_NULL
 *         self.zst.zfree = Z_NULL
 *         self.zst.next_in = NULL             # <<<<<<<<<<<<<<
 *         self.zst.next_out = NULL
 *         self.zst.total_in = 0u
 */
  __pyx_v_self->zst.next_in = NULL;

  /* "fastwarc/stream_io.pyx":356
 *         self.zst.zfree = Z_NULL
 *         self.zst.next_in = NULL
 *         self.zst.next_out = NULL             # <<<<<<<<<<<<<<
 *         self.zst.total_in = 0u
 *         self.zst.total_out = 0u
 */
  __pyx_v_self->zst.next_out = NULL;

  /* "fastwarc/stream_io.pyx":357
 *         self.zst.next_in = NULL
 *         self.zst.next_out = NULL
 *         self.zst.total_in = 0u             # <<<<<<<<<<<<<<
 *         self.zst.total_out = 0u
 *         self.zst.avail_in = 0u
 */
  __pyx_v_self->zst.total_in = 0U;

  /* "fastwarc/stream_io.pyx":358
 *         self.zst.next_out = NULL
 *         self.zst.total_in = 0u
 *         self.zst.total_out = 0u             # <<<<<<<<<<<<<<
 *         self.zst.avail_in = 0u
 *         self.zst.avail_out = 0u
 */
  __pyx_v_self->zst.total_out = 0U;

  /* "fastwarc/stream_io.pyx":359
 *         self.zst.total_in = 0u
 *         self.zst.total_out = 0u
 *         self.zst.avail_in = 0u             # <<<<<<<<<<<<<<
 *         self.zst.avail_out = 0u
 *         self.working_buf.clear()
 */
  __pyx_v_self->zst.avail_in = 0U;

  /* "fastwarc/stream_io.pyx":360
 *         self.zst.total_out = 0u
 *         self.zst.avail_in = 0u
 *         self.zst.avail_out = 0u             # <<<<<<<<<<<<<<
 *         self.working_buf.clear()
 * 
 */
  __pyx_v_self->zst.avail_out = 0U;

  /* "fastwarc/stream_io.pyx":361
 *         self.zst.avail_in = 0u
 *         self.zst.avail_out = 0u
 *         self.working_buf.clear()             # <<<<<<<<<<<<<<
 * 
 *         if deflate:
 */
  __pyx_v_self->working_buf.clear();

  /* "fastwarc/stream_io.pyx":363
 *         self.working_buf.clear()
 * 
 *         if deflate:             # <<<<<<<<<<<<<<
 *             deflateInit2(&self.zst, self.compression_level, Z_DEFLATED, self.window_bits, 9, Z_DEFAULT_STRATEGY)
 *             self.stream_state = CompressingStreamState.COMPRESSING
 */
  __pyx_t_1 = (__pyx_v_deflate != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":364
 * 
 *         if deflate:
 *             deflateInit2(&self.zst, self.compression_level, Z_DEFLATED, self.window_bits, 9, Z_DEFAULT_STRATEGY)             # <<<<<<<<<<<<<<
 *             self.stream_state = CompressingStreamState.COMPRESSING
 *         else:
 */
    (void)(deflateInit2((&__pyx_v_self->zst), __pyx_v_self->compression_level, Z_DEFLATED, __pyx_v_self->window_bits, 9, Z_DEFAULT_STRATEGY));

    /* "fastwarc/stream_io.pyx":365
 *         if deflate:
 *             deflateInit2(&self.zst, self.compression_level, Z_DEFLATED, self.window_bits, 9, Z_DEFAULT_STRATEGY)
 *             self.stream_state = CompressingStreamState.COMPRESSING             # <<<<<<<<<<<<<<
 *         else:
 *             inflateInit2(&self.zst, self.window_bits)
 */
    __pyx_v_self->stream_state = COMPRESSING;

    /* "fastwarc/stream_io.pyx":363
 *         self.working_buf.clear()
 * 
 *         if deflate:             # <<<<<<<<<<<<<<
 *             deflateInit2(&self.zst, self.compression_level, Z_DEFLATED, self.window_bits, 9, Z_DEFAULT_STRATEGY)
 *             self.stream_state = CompressingStreamState.COMPRESSING
 */
    goto __pyx_L4;
  }

  /* "fastwarc/stream_io.pyx":367
 *             self.stream_state = CompressingStreamState.COMPRESSING
 *         else:
 *             inflateInit2(&self.zst, self.window_bits)             # <<<<<<<<<<<<<<
 *             self.stream_state = CompressingStreamState.DECOMPRESSING
 * 
 */
  /*else*/ {
    (void)(inflateInit2((&__pyx_v_self->zst), __pyx_v_self->window_bits));

    /* "fastwarc/stream_io.pyx":368
 *         else:
 *             inflateInit2(&self.zst, self.window_bits)
 *             self.stream_state = CompressingStreamState.DECOMPRESSING             # <<<<<<<<<<<<<<
 * 
 *     cdef void prepopulate(self, bint deflate, const string& initial_data):
 */
    __pyx_v_self->stream_state = DECOMPRESSING;
  }
  __pyx_L4:;

  /* "fastwarc/stream_io.pyx":342
 *         return self.stream_pos
 * 
 *     cdef void _init_z_stream(self, bint deflate) nogil:             # <<<<<<<<<<<<<<
 *         """
 *         Reset internal state and initialize ``z_stream``.
 */

  /* function exit code */
  __pyx_L0:;
}

/* "fastwarc/stream_io.pyx":370
 *             self.stream_state = CompressingStreamState.DECOMPRESSING
 * 
 *     cdef void prepopulate(self, bint deflate, const string& initial_data):             # <<<<<<<<<<<<<<
 *         """
 *         Fill internal working buffer with initial data.
 */

static void __pyx_f_8fastwarc_9stream_io_10GZipStream_prepopulate(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, int __pyx_v_deflate, std::string const &__pyx_v_initial_data) {
  __Pyx_RefNannyDeclarations
  unsigned int __pyx_t_1;
  size_t __pyx_t_2;
  size_t __pyx_t_3;
  unsigned long __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("prepopulate", 0);

  /* "fastwarc/stream_io.pyx":379
 *         :param initial_data: data to pre-populate
 *         """
 *         self._init_z_stream(deflate)             # <<<<<<<<<<<<<<
 *         self.working_buf.append(initial_data)
 *         self.working_buf_filled += <unsigned int>initial_data.size()
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_init_z_stream(__pyx_v_self, __pyx_v_deflate);

  /* "fastwarc/stream_io.pyx":380
 *         """
 *         self._init_z_stream(deflate)
 *         self.working_buf.append(initial_data)             # <<<<<<<<<<<<<<
 *         self.working_buf_filled += <unsigned int>initial_data.size()
 *         self.zst.next_in = <Bytef*>self.working_buf.data()
 */
  try {
    __pyx_v_self->working_buf.append(__pyx_v_initial_data);
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 380, __pyx_L1_error)
  }

  /* "fastwarc/stream_io.pyx":381
 *         self._init_z_stream(deflate)
 *         self.working_buf.append(initial_data)
 *         self.working_buf_filled += <unsigned int>initial_data.size()             # <<<<<<<<<<<<<<
 *         self.zst.next_in = <Bytef*>self.working_buf.data()
 *         self.zst.avail_in = self.working_buf_filled
 */
  __pyx_v_self->working_buf_filled = (__pyx_v_self->working_buf_filled + ((unsigned int)__pyx_v_initial_data.size()));

  /* "fastwarc/stream_io.pyx":382
 *         self.working_buf.append(initial_data)
 *         self.working_buf_filled += <unsigned int>initial_data.size()
 *         self.zst.next_in = <Bytef*>self.working_buf.data()             # <<<<<<<<<<<<<<
 *         self.zst.avail_in = self.working_buf_filled
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)
 */
  __pyx_v_self->zst.next_in = ((Bytef *)__pyx_v_self->working_buf.data());

  /* "fastwarc/stream_io.pyx":383
 *         self.working_buf_filled += <unsigned int>initial_data.size()
 *         self.zst.next_in = <Bytef*>self.working_buf.data()
 *         self.zst.avail_in = self.working_buf_filled             # <<<<<<<<<<<<<<
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)
 * 
 */
  __pyx_t_1 = __pyx_v_self->working_buf_filled;
  __pyx_v_self->zst.avail_in = __pyx_t_1;

  /* "fastwarc/stream_io.pyx":384
 *         self.zst.next_in = <Bytef*>self.working_buf.data()
 *         self.zst.avail_in = self.working_buf_filled
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)             # <<<<<<<<<<<<<<
 * 
 *     cdef void _free_z_stream(self) nogil:
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->tell(__pyx_v_self->raw_stream); if (unlikely(__pyx_t_2 == ((size_t)-1L))) __PYX_ERR(1, 384, __pyx_L1_error)
  __pyx_t_3 = (__pyx_t_2 - __pyx_v_self->working_buf_filled);
  __pyx_t_4 = 0U;
  if (((__pyx_t_3 > __pyx_t_4) != 0)) {
    __pyx_t_2 = __pyx_t_3;
  } else {
    __pyx_t_2 = __pyx_t_4;
  }
  __pyx_v_self->stream_pos = __pyx_t_2;

  /* "fastwarc/stream_io.pyx":370
 *             self.stream_state = CompressingStreamState.DECOMPRESSING
 * 
 *     cdef void prepopulate(self, bint deflate, const string& initial_data):             # <<<<<<<<<<<<<<
 *         """
 *         Fill internal working buffer with initial data.
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("fastwarc.stream_io.GZipStream.prepopulate", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":386
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)
 * 
 *     cdef void _free_z_stream(self) nogil:             # <<<<<<<<<<<<<<
 *         """Release internal state and reset working buffer."""
 *         if self.stream_state == CompressingStreamState.UNINIT:
 */

static void __pyx_f_8fastwarc_9stream_io_10GZipStream__free_z_stream(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self) {
  int __pyx_t_1;

  /* "fastwarc/stream_io.pyx":388
 *     cdef void _free_z_stream(self) nogil:
 *         """Release internal state and reset working buffer."""
 *         if self.stream_state == CompressingStreamState.UNINIT:             # <<<<<<<<<<<<<<
 *             return
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 */
  __pyx_t_1 = ((__pyx_v_self->stream_state == UNINIT) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":389
 *         """Release internal state and reset working buffer."""
 *         if self.stream_state == CompressingStreamState.UNINIT:
 *             return             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             deflateEnd(&self.zst)
 */
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":388
 *     cdef void _free_z_stream(self) nogil:
 *         """Release internal state and reset working buffer."""
 *         if self.stream_state == CompressingStreamState.UNINIT:             # <<<<<<<<<<<<<<
 *             return
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 */
  }

  /* "fastwarc/stream_io.pyx":390
 *         if self.stream_state == CompressingStreamState.UNINIT:
 *             return
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             deflateEnd(&self.zst)
 *         elif self.stream_state == CompressingStreamState.DECOMPRESSING:
 */
  switch (__pyx_v_self->stream_state) {
    case COMPRESSING:

    /* "fastwarc/stream_io.pyx":391
 *             return
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             deflateEnd(&self.zst)             # <<<<<<<<<<<<<<
 *         elif self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             inflateEnd(&self.zst)
 */
    (void)(deflateEnd((&__pyx_v_self->zst)));

    /* "fastwarc/stream_io.pyx":390
 *         if self.stream_state == CompressingStreamState.UNINIT:
 *             return
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             deflateEnd(&self.zst)
 *         elif self.stream_state == CompressingStreamState.DECOMPRESSING:
 */
    break;
    case DECOMPRESSING:

    /* "fastwarc/stream_io.pyx":393
 *             deflateEnd(&self.zst)
 *         elif self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             inflateEnd(&self.zst)             # <<<<<<<<<<<<<<
 *         self.working_buf.clear()
 *         self.working_buf_filled = 0u
 */
    (void)(inflateEnd((&__pyx_v_self->zst)));

    /* "fastwarc/stream_io.pyx":392
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             deflateEnd(&self.zst)
 *         elif self.stream_state == CompressingStreamState.DECOMPRESSING:             # <<<<<<<<<<<<<<
 *             inflateEnd(&self.zst)
 *         self.working_buf.clear()
 */
    break;
    default: break;
  }

  /* "fastwarc/stream_io.pyx":394
 *         elif self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             inflateEnd(&self.zst)
 *         self.working_buf.clear()             # <<<<<<<<<<<<<<
 *         self.working_buf_filled = 0u
 *         self.stream_state = CompressingStreamState.UNINIT
 */
  __pyx_v_self->working_buf.clear();

  /* "fastwarc/stream_io.pyx":395
 *             inflateEnd(&self.zst)
 *         self.working_buf.clear()
 *         self.working_buf_filled = 0u             # <<<<<<<<<<<<<<
 *         self.stream_state = CompressingStreamState.UNINIT
 * 
 */
  __pyx_v_self->working_buf_filled = 0U;

  /* "fastwarc/stream_io.pyx":396
 *         self.working_buf.clear()
 *         self.working_buf_filled = 0u
 *         self.stream_state = CompressingStreamState.UNINIT             # <<<<<<<<<<<<<<
 * 
 *     cdef void _reinit_z_stream(self, bint deflate) nogil:
 */
  __pyx_v_self->stream_state = UNINIT;

  /* "fastwarc/stream_io.pyx":386
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)
 * 
 *     cdef void _free_z_stream(self) nogil:             # <<<<<<<<<<<<<<
 *         """Release internal state and reset working buffer."""
 *         if self.stream_state == CompressingStreamState.UNINIT:
 */

  /* function exit code */
  __pyx_L0:;
}

/* "fastwarc/stream_io.pyx":398
 *         self.stream_state = CompressingStreamState.UNINIT
 * 
 *     cdef void _reinit_z_stream(self, bint deflate) nogil:             # <<<<<<<<<<<<<<
 *         """Re-initialize zstream, but retain working buffer. Use to restart stream with different window parameters."""
 * 
 */

static void __pyx_f_8fastwarc_9stream_io_10GZipStream__reinit_z_stream(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, int __pyx_v_deflate) {
  std::string __pyx_v_working_buf_tmp;
  __Pyx_RefNannyDeclarations
  std::string __pyx_t_1;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_RefNannySetupContext("_reinit_z_stream", 0);
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif

  /* "fastwarc/stream_io.pyx":399
 * 
 *     cdef void _reinit_z_stream(self, bint deflate) nogil:
 *         """Re-initialize zstream, but retain working buffer. Use to restart stream with different window parameters."""             # <<<<<<<<<<<<<<
 * 
 *         cdef string working_buf_tmp = self.working_buf.substr(0, self.working_buf_filled)
 */
  /*try:*/ {

    /* "fastwarc/stream_io.pyx":401
 *         """Re-initialize zstream, but retain working buffer. Use to restart stream with different window parameters."""
 * 
 *         cdef string working_buf_tmp = self.working_buf.substr(0, self.working_buf_filled)             # <<<<<<<<<<<<<<
 *         if self.stream_state != CompressingStreamState.UNINIT:
 *             self.zst.next_out = NULL
 */
    try {
      __pyx_t_1 = __pyx_v_self->working_buf.substr(0, __pyx_v_self->working_buf_filled);
    } catch(...) {
      #ifdef WITH_THREAD
      PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
      #endif
      __Pyx_CppExn2PyErr();
      #ifdef WITH_THREAD
      __Pyx_PyGILState_Release(__pyx_gilstate_save);
      #endif
      __PYX_ERR(1, 401, __pyx_L4_error)
    }
    __pyx_v_working_buf_tmp = __pyx_t_1;

    /* "fastwarc/stream_io.pyx":402
 * 
 *         cdef string working_buf_tmp = self.working_buf.substr(0, self.working_buf_filled)
 *         if self.stream_state != CompressingStreamState.UNINIT:             # <<<<<<<<<<<<<<
 *             self.zst.next_out = NULL
 *             self.zst.avail_out = 0u
 */
    __pyx_t_2 = ((__pyx_v_self->stream_state != UNINIT) != 0);
    if (__pyx_t_2) {

      /* "fastwarc/stream_io.pyx":403
 *         cdef string working_buf_tmp = self.working_buf.substr(0, self.working_buf_filled)
 *         if self.stream_state != CompressingStreamState.UNINIT:
 *             self.zst.next_out = NULL             # <<<<<<<<<<<<<<
 *             self.zst.avail_out = 0u
 *             self._free_z_stream()
 */
      __pyx_v_self->zst.next_out = NULL;

      /* "fastwarc/stream_io.pyx":404
 *         if self.stream_state != CompressingStreamState.UNINIT:
 *             self.zst.next_out = NULL
 *             self.zst.avail_out = 0u             # <<<<<<<<<<<<<<
 *             self._free_z_stream()
 *         with gil:
 */
      __pyx_v_self->zst.avail_out = 0U;

      /* "fastwarc/stream_io.pyx":405
 *             self.zst.next_out = NULL
 *             self.zst.avail_out = 0u
 *             self._free_z_stream()             # <<<<<<<<<<<<<<
 *         with gil:
 *             self.prepopulate(deflate, working_buf_tmp)
 */
      ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_free_z_stream(__pyx_v_self);

      /* "fastwarc/stream_io.pyx":402
 * 
 *         cdef string working_buf_tmp = self.working_buf.substr(0, self.working_buf_filled)
 *         if self.stream_state != CompressingStreamState.UNINIT:             # <<<<<<<<<<<<<<
 *             self.zst.next_out = NULL
 *             self.zst.avail_out = 0u
 */
    }

    /* "fastwarc/stream_io.pyx":406
 *             self.zst.avail_out = 0u
 *             self._free_z_stream()
 *         with gil:             # <<<<<<<<<<<<<<
 *             self.prepopulate(deflate, working_buf_tmp)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
        #endif
        /*try:*/ {

          /* "fastwarc/stream_io.pyx":407
 *             self._free_z_stream()
 *         with gil:
 *             self.prepopulate(deflate, working_buf_tmp)             # <<<<<<<<<<<<<<
 * 
 *     cdef bint _refill_working_buf(self, size_t size) except -1:
 */
          ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->prepopulate(__pyx_v_self, __pyx_v_deflate, __pyx_v_working_buf_tmp);
        }

        /* "fastwarc/stream_io.pyx":406
 *             self.zst.avail_out = 0u
 *             self._free_z_stream()
 *         with gil:             # <<<<<<<<<<<<<<
 *             self.prepopulate(deflate, working_buf_tmp)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_PyGILState_Release(__pyx_gilstate_save);
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }
  }

  /* "fastwarc/stream_io.pyx":399
 * 
 *     cdef void _reinit_z_stream(self, bint deflate) nogil:
 *         """Re-initialize zstream, but retain working buffer. Use to restart stream with different window parameters."""             # <<<<<<<<<<<<<<
 * 
 *         cdef string working_buf_tmp = self.working_buf.substr(0, self.working_buf_filled)
 */
  /*finally:*/ {
    /*normal exit:*/{
      #ifdef WITH_THREAD
      __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
      #endif
      goto __pyx_L5;
    }
    __pyx_L4_error: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
      #endif
      goto __pyx_L1_error;
    }
    __pyx_L5:;
  }

  /* "fastwarc/stream_io.pyx":398
 *         self.stream_state = CompressingStreamState.UNINIT
 * 
 *     cdef void _reinit_z_stream(self, bint deflate) nogil:             # <<<<<<<<<<<<<<
 *         """Re-initialize zstream, but retain working buffer. Use to restart stream with different window parameters."""
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("fastwarc.stream_io.GZipStream._reinit_z_stream", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1);
  __pyx_L0:;
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
}

/* "fastwarc/stream_io.pyx":409
 *             self.prepopulate(deflate, working_buf_tmp)
 * 
 *     cdef bint _refill_working_buf(self, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.zst.avail_in > 0:
 *             return True
 */

static int __pyx_f_8fastwarc_9stream_io_10GZipStream__refill_working_buf(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, size_t __pyx_v_size) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  size_t __pyx_t_2;
  unsigned int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_refill_working_buf", 0);

  /* "fastwarc/stream_io.pyx":410
 * 
 *     cdef bint _refill_working_buf(self, size_t size) except -1:
 *         if self.zst.avail_in > 0:             # <<<<<<<<<<<<<<
 *             return True
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->zst.avail_in > 0) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":411
 *     cdef bint _refill_working_buf(self, size_t size) except -1:
 *         if self.zst.avail_in > 0:
 *             return True             # <<<<<<<<<<<<<<
 * 
 *         if self.working_buf.size() < size:
 */
    __pyx_r = 1;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":410
 * 
 *     cdef bint _refill_working_buf(self, size_t size) except -1:
 *         if self.zst.avail_in > 0:             # <<<<<<<<<<<<<<
 *             return True
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":413
 *             return True
 * 
 *         if self.working_buf.size() < size:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(size)
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->working_buf.size() < __pyx_v_size) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":414
 * 
 *         if self.working_buf.size() < size:
 *             self.working_buf.resize(size)             # <<<<<<<<<<<<<<
 * 
 *         self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)
 */
    try {
      __pyx_v_self->working_buf.resize(__pyx_v_size);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 414, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":413
 *             return True
 * 
 *         if self.working_buf.size() < size:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(size)
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":416
 *             self.working_buf.resize(size)
 * 
 *         self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)             # <<<<<<<<<<<<<<
 *         if self.working_buf_filled == 0:
 *             # EOF
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->read(__pyx_v_self->raw_stream, __pyx_v_self->working_buf.data(), __pyx_v_size); if (unlikely(__pyx_t_2 == ((size_t)-1L))) __PYX_ERR(1, 416, __pyx_L1_error)
  __pyx_v_self->working_buf_filled = ((unsigned int)__pyx_t_2);

  /* "fastwarc/stream_io.pyx":417
 * 
 *         self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)
 *         if self.working_buf_filled == 0:             # <<<<<<<<<<<<<<
 *             # EOF
 *             self._free_z_stream()
 */
  __pyx_t_1 = ((__pyx_v_self->working_buf_filled == 0) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":419
 *         if self.working_buf_filled == 0:
 *             # EOF
 *             self._free_z_stream()             # <<<<<<<<<<<<<<
 *             return False
 * 
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_free_z_stream(__pyx_v_self);

    /* "fastwarc/stream_io.pyx":420
 *             # EOF
 *             self._free_z_stream()
 *             return False             # <<<<<<<<<<<<<<
 * 
 *         self.zst.next_in = <Bytef*>self.working_buf.data()
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":417
 * 
 *         self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)
 *         if self.working_buf_filled == 0:             # <<<<<<<<<<<<<<
 *             # EOF
 *             self._free_z_stream()
 */
  }

  /* "fastwarc/stream_io.pyx":422
 *             return False
 * 
 *         self.zst.next_in = <Bytef*>self.working_buf.data()             # <<<<<<<<<<<<<<
 *         self.zst.avail_in = self.working_buf_filled
 *         return True
 */
  __pyx_v_self->zst.next_in = ((Bytef *)__pyx_v_self->working_buf.data());

  /* "fastwarc/stream_io.pyx":423
 * 
 *         self.zst.next_in = <Bytef*>self.working_buf.data()
 *         self.zst.avail_in = self.working_buf_filled             # <<<<<<<<<<<<<<
 *         return True
 * 
 */
  __pyx_t_3 = __pyx_v_self->working_buf_filled;
  __pyx_v_self->zst.avail_in = __pyx_t_3;

  /* "fastwarc/stream_io.pyx":424
 *         self.zst.next_in = <Bytef*>self.working_buf.data()
 *         self.zst.avail_in = self.working_buf_filled
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":409
 *             self.prepopulate(deflate, working_buf_tmp)
 * 
 *     cdef bint _refill_working_buf(self, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.zst.avail_in > 0:
 *             return True
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.GZipStream._refill_working_buf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":426
 *         return True
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             raise StreamError('Compression in progress.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_read(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size) {
  int __pyx_v_stream_read_status;
  size_t __pyx_v_read_so_far;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  char __pyx_t_7;
  unsigned long __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("read", 0);

  /* "fastwarc/stream_io.pyx":427
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             raise StreamError('Compression in progress.')
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->stream_state == COMPRESSING) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":428
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             raise StreamError('Compression in progress.')             # <<<<<<<<<<<<<<
 * 
 *         # Init stream if this is the first read
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 428, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_Compression_in_progress) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_Compression_in_progress);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 428, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 428, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":427
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             raise StreamError('Compression in progress.')
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":431
 * 
 *         # Init stream if this is the first read
 *         if self.stream_state == CompressingStreamState.UNINIT:             # <<<<<<<<<<<<<<
 *             self._init_z_stream(False)
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->stream_state == UNINIT) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":432
 *         # Init stream if this is the first read
 *         if self.stream_state == CompressingStreamState.UNINIT:
 *             self._init_z_stream(False)             # <<<<<<<<<<<<<<
 * 
 *             # If reader is in deflate / zlib format mode, check if first bytes are a zlib header
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_init_z_stream(__pyx_v_self, 0);

    /* "fastwarc/stream_io.pyx":435
 * 
 *             # If reader is in deflate / zlib format mode, check if first bytes are a zlib header
 *             if self.window_bits == MAX_WBITS:             # <<<<<<<<<<<<<<
 *                 if not self._refill_working_buf(size) or self.working_buf.size() < 2:
 *                     return 0
 */
    __pyx_t_1 = ((__pyx_v_self->window_bits == MAX_WBITS) != 0);
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":436
 *             # If reader is in deflate / zlib format mode, check if first bytes are a zlib header
 *             if self.window_bits == MAX_WBITS:
 *                 if not self._refill_working_buf(size) or self.working_buf.size() < 2:             # <<<<<<<<<<<<<<
 *                     return 0
 *                 if not (self.working_buf[0] == b'\x78' and self.working_buf[1] in [b'\x01', b'\xef', b'\x9c', b'\xda']):
 */
      __pyx_t_5 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_refill_working_buf(__pyx_v_self, __pyx_v_size); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 436, __pyx_L1_error)
      __pyx_t_6 = ((!(__pyx_t_5 != 0)) != 0);
      if (!__pyx_t_6) {
      } else {
        __pyx_t_1 = __pyx_t_6;
        goto __pyx_L7_bool_binop_done;
      }
      __pyx_t_6 = ((__pyx_v_self->working_buf.size() < 2) != 0);
      __pyx_t_1 = __pyx_t_6;
      __pyx_L7_bool_binop_done:;
      if (__pyx_t_1) {

        /* "fastwarc/stream_io.pyx":437
 *             if self.window_bits == MAX_WBITS:
 *                 if not self._refill_working_buf(size) or self.working_buf.size() < 2:
 *                     return 0             # <<<<<<<<<<<<<<
 *                 if not (self.working_buf[0] == b'\x78' and self.working_buf[1] in [b'\x01', b'\xef', b'\x9c', b'\xda']):
 *                     # Re-init as "raw" deflate stream if no zlib header found
 */
        __pyx_r = 0;
        goto __pyx_L0;

        /* "fastwarc/stream_io.pyx":436
 *             # If reader is in deflate / zlib format mode, check if first bytes are a zlib header
 *             if self.window_bits == MAX_WBITS:
 *                 if not self._refill_working_buf(size) or self.working_buf.size() < 2:             # <<<<<<<<<<<<<<
 *                     return 0
 *                 if not (self.working_buf[0] == b'\x78' and self.working_buf[1] in [b'\x01', b'\xef', b'\x9c', b'\xda']):
 */
      }

      /* "fastwarc/stream_io.pyx":438
 *                 if not self._refill_working_buf(size) or self.working_buf.size() < 2:
 *                     return 0
 *                 if not (self.working_buf[0] == b'\x78' and self.working_buf[1] in [b'\x01', b'\xef', b'\x9c', b'\xda']):             # <<<<<<<<<<<<<<
 *                     # Re-init as "raw" deflate stream if no zlib header found
 *                     self.window_bits = -MAX_WBITS
 */
      __pyx_t_6 = (((__pyx_v_self->working_buf[0]) == 'x') != 0);
      if (__pyx_t_6) {
      } else {
        __pyx_t_1 = __pyx_t_6;
        goto __pyx_L10_bool_binop_done;
      }
      __pyx_t_7 = (__pyx_v_self->working_buf[1]);
      __pyx_t_5 = ((__pyx_t_7 == '\x01') != 0);
      if (!__pyx_t_5) {
      } else {
        __pyx_t_6 = __pyx_t_5;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_5 = ((__pyx_t_7 == '\xEF') != 0);
      if (!__pyx_t_5) {
      } else {
        __pyx_t_6 = __pyx_t_5;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_5 = ((__pyx_t_7 == '\x9C') != 0);
      if (!__pyx_t_5) {
      } else {
        __pyx_t_6 = __pyx_t_5;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_5 = ((__pyx_t_7 == '\xDA') != 0);
      __pyx_t_6 = __pyx_t_5;
      __pyx_L12_bool_binop_done:;
      __pyx_t_5 = (__pyx_t_6 != 0);
      __pyx_t_1 = __pyx_t_5;
      __pyx_L10_bool_binop_done:;
      __pyx_t_5 = ((!__pyx_t_1) != 0);
      if (__pyx_t_5) {

        /* "fastwarc/stream_io.pyx":440
 *                 if not (self.working_buf[0] == b'\x78' and self.working_buf[1] in [b'\x01', b'\xef', b'\x9c', b'\xda']):
 *                     # Re-init as "raw" deflate stream if no zlib header found
 *                     self.window_bits = -MAX_WBITS             # <<<<<<<<<<<<<<
 *                     self._reinit_z_stream(False)
 * 
 */
        __pyx_v_self->window_bits = (-MAX_WBITS);

        /* "fastwarc/stream_io.pyx":441
 *                     # Re-init as "raw" deflate stream if no zlib header found
 *                     self.window_bits = -MAX_WBITS
 *                     self._reinit_z_stream(False)             # <<<<<<<<<<<<<<
 * 
 *         if self.zst.avail_in == 0 or self.working_buf.empty():
 */
        ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_reinit_z_stream(__pyx_v_self, 0);

        /* "fastwarc/stream_io.pyx":438
 *                 if not self._refill_working_buf(size) or self.working_buf.size() < 2:
 *                     return 0
 *                 if not (self.working_buf[0] == b'\x78' and self.working_buf[1] in [b'\x01', b'\xef', b'\x9c', b'\xda']):             # <<<<<<<<<<<<<<
 *                     # Re-init as "raw" deflate stream if no zlib header found
 *                     self.window_bits = -MAX_WBITS
 */
      }

      /* "fastwarc/stream_io.pyx":435
 * 
 *             # If reader is in deflate / zlib format mode, check if first bytes are a zlib header
 *             if self.window_bits == MAX_WBITS:             # <<<<<<<<<<<<<<
 *                 if not self._refill_working_buf(size) or self.working_buf.size() < 2:
 *                     return 0
 */
    }

    /* "fastwarc/stream_io.pyx":431
 * 
 *         # Init stream if this is the first read
 *         if self.stream_state == CompressingStreamState.UNINIT:             # <<<<<<<<<<<<<<
 *             self._init_z_stream(False)
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":443
 *                     self._reinit_z_stream(False)
 * 
 *         if self.zst.avail_in == 0 or self.working_buf.empty():             # <<<<<<<<<<<<<<
 *             if not self._refill_working_buf(size):
 *                 return 0
 */
  __pyx_t_1 = ((__pyx_v_self->zst.avail_in == 0) != 0);
  if (!__pyx_t_1) {
  } else {
    __pyx_t_5 = __pyx_t_1;
    goto __pyx_L17_bool_binop_done;
  }
  __pyx_t_1 = (__pyx_v_self->working_buf.empty() != 0);
  __pyx_t_5 = __pyx_t_1;
  __pyx_L17_bool_binop_done:;
  if (__pyx_t_5) {

    /* "fastwarc/stream_io.pyx":444
 * 
 *         if self.zst.avail_in == 0 or self.working_buf.empty():
 *             if not self._refill_working_buf(size):             # <<<<<<<<<<<<<<
 *                 return 0
 * 
 */
    __pyx_t_5 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_refill_working_buf(__pyx_v_self, __pyx_v_size); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 444, __pyx_L1_error)
    __pyx_t_1 = ((!(__pyx_t_5 != 0)) != 0);
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":445
 *         if self.zst.avail_in == 0 or self.working_buf.empty():
 *             if not self._refill_working_buf(size):
 *                 return 0             # <<<<<<<<<<<<<<
 * 
 *         self.zst.next_out = <Bytef*>out
 */
      __pyx_r = 0;
      goto __pyx_L0;

      /* "fastwarc/stream_io.pyx":444
 * 
 *         if self.zst.avail_in == 0 or self.working_buf.empty():
 *             if not self._refill_working_buf(size):             # <<<<<<<<<<<<<<
 *                 return 0
 * 
 */
    }

    /* "fastwarc/stream_io.pyx":443
 *                     self._reinit_z_stream(False)
 * 
 *         if self.zst.avail_in == 0 or self.working_buf.empty():             # <<<<<<<<<<<<<<
 *             if not self._refill_working_buf(size):
 *                 return 0
 */
  }

  /* "fastwarc/stream_io.pyx":447
 *                 return 0
 * 
 *         self.zst.next_out = <Bytef*>out             # <<<<<<<<<<<<<<
 *         self.zst.avail_out = <unsigned int>size
 *         cdef int stream_read_status = Z_STREAM_END
 */
  __pyx_v_self->zst.next_out = ((Bytef *)__pyx_v_out);

  /* "fastwarc/stream_io.pyx":448
 * 
 *         self.zst.next_out = <Bytef*>out
 *         self.zst.avail_out = <unsigned int>size             # <<<<<<<<<<<<<<
 *         cdef int stream_read_status = Z_STREAM_END
 *         cdef size_t read_so_far = self.zst.total_in
 */
  __pyx_v_self->zst.avail_out = ((unsigned int)__pyx_v_size);

  /* "fastwarc/stream_io.pyx":449
 *         self.zst.next_out = <Bytef*>out
 *         self.zst.avail_out = <unsigned int>size
 *         cdef int stream_read_status = Z_STREAM_END             # <<<<<<<<<<<<<<
 *         cdef size_t read_so_far = self.zst.total_in
 * 
 */
  __pyx_v_stream_read_status = Z_STREAM_END;

  /* "fastwarc/stream_io.pyx":450
 *         self.zst.avail_out = <unsigned int>size
 *         cdef int stream_read_status = Z_STREAM_END
 *         cdef size_t read_so_far = self.zst.total_in             # <<<<<<<<<<<<<<
 * 
 *         while True:
 */
  __pyx_t_8 = __pyx_v_self->zst.total_in;
  __pyx_v_read_so_far = __pyx_t_8;

  /* "fastwarc/stream_io.pyx":452
 *         cdef size_t read_so_far = self.zst.total_in
 * 
 *         while True:             # <<<<<<<<<<<<<<
 *             stream_read_status = inflate(&self.zst, Z_NO_FLUSH)
 *             if self.zst.avail_out == 0 or (stream_read_status != Z_OK and stream_read_status != Z_BUF_ERROR):
 */
  while (1) {

    /* "fastwarc/stream_io.pyx":453
 * 
 *         while True:
 *             stream_read_status = inflate(&self.zst, Z_NO_FLUSH)             # <<<<<<<<<<<<<<
 *             if self.zst.avail_out == 0 or (stream_read_status != Z_OK and stream_read_status != Z_BUF_ERROR):
 *                 break
 */
    __pyx_v_stream_read_status = inflate((&__pyx_v_self->zst), Z_NO_FLUSH);

    /* "fastwarc/stream_io.pyx":454
 *         while True:
 *             stream_read_status = inflate(&self.zst, Z_NO_FLUSH)
 *             if self.zst.avail_out == 0 or (stream_read_status != Z_OK and stream_read_status != Z_BUF_ERROR):             # <<<<<<<<<<<<<<
 *                 break
 *             if self.zst.avail_in == 0 and not self._refill_working_buf(size):
 */
    __pyx_t_5 = ((__pyx_v_self->zst.avail_out == 0) != 0);
    if (!__pyx_t_5) {
    } else {
      __pyx_t_1 = __pyx_t_5;
      goto __pyx_L23_bool_binop_done;
    }
    __pyx_t_5 = ((__pyx_v_stream_read_status != Z_OK) != 0);
    if (__pyx_t_5) {
    } else {
      __pyx_t_1 = __pyx_t_5;
      goto __pyx_L23_bool_binop_done;
    }
    __pyx_t_5 = ((__pyx_v_stream_read_status != Z_BUF_ERROR) != 0);
    __pyx_t_1 = __pyx_t_5;
    __pyx_L23_bool_binop_done:;
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":455
 *             stream_read_status = inflate(&self.zst, Z_NO_FLUSH)
 *             if self.zst.avail_out == 0 or (stream_read_status != Z_OK and stream_read_status != Z_BUF_ERROR):
 *                 break             # <<<<<<<<<<<<<<
 *             if self.zst.avail_in == 0 and not self._refill_working_buf(size):
 *                 break
 */
      goto __pyx_L21_break;

      /* "fastwarc/stream_io.pyx":454
 *         while True:
 *             stream_read_status = inflate(&self.zst, Z_NO_FLUSH)
 *             if self.zst.avail_out == 0 or (stream_read_status != Z_OK and stream_read_status != Z_BUF_ERROR):             # <<<<<<<<<<<<<<
 *                 break
 *             if self.zst.avail_in == 0 and not self._refill_working_buf(size):
 */
    }

    /* "fastwarc/stream_io.pyx":456
 *             if self.zst.avail_out == 0 or (stream_read_status != Z_OK and stream_read_status != Z_BUF_ERROR):
 *                 break
 *             if self.zst.avail_in == 0 and not self._refill_working_buf(size):             # <<<<<<<<<<<<<<
 *                 break
 *         self.stream_pos += self.zst.total_in - read_so_far
 */
    __pyx_t_5 = ((__pyx_v_self->zst.avail_in == 0) != 0);
    if (__pyx_t_5) {
    } else {
      __pyx_t_1 = __pyx_t_5;
      goto __pyx_L27_bool_binop_done;
    }
    __pyx_t_5 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_refill_working_buf(__pyx_v_self, __pyx_v_size); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 456, __pyx_L1_error)
    __pyx_t_6 = ((!(__pyx_t_5 != 0)) != 0);
    __pyx_t_1 = __pyx_t_6;
    __pyx_L27_bool_binop_done:;
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":457
 *                 break
 *             if self.zst.avail_in == 0 and not self._refill_working_buf(size):
 *                 break             # <<<<<<<<<<<<<<
 *         self.stream_pos += self.zst.total_in - read_so_far
 * 
 */
      goto __pyx_L21_break;

      /* "fastwarc/stream_io.pyx":456
 *             if self.zst.avail_out == 0 or (stream_read_status != Z_OK and stream_read_status != Z_BUF_ERROR):
 *                 break
 *             if self.zst.avail_in == 0 and not self._refill_working_buf(size):             # <<<<<<<<<<<<<<
 *                 break
 *         self.stream_pos += self.zst.total_in - read_so_far
 */
    }
  }
  __pyx_L21_break:;

  /* "fastwarc/stream_io.pyx":458
 *             if self.zst.avail_in == 0 and not self._refill_working_buf(size):
 *                 break
 *         self.stream_pos += self.zst.total_in - read_so_far             # <<<<<<<<<<<<<<
 * 
 *         # Error
 */
  __pyx_v_self->stream_pos = (__pyx_v_self->stream_pos + (__pyx_v_self->zst.total_in - __pyx_v_read_so_far));

  /* "fastwarc/stream_io.pyx":461
 * 
 *         # Error
 *         if stream_read_status < 0 and stream_read_status != Z_BUF_ERROR:             # <<<<<<<<<<<<<<
 *             self._free_z_stream()
 *             raise StreamError('Not a valid GZip stream')
 */
  __pyx_t_6 = ((__pyx_v_stream_read_status < 0) != 0);
  if (__pyx_t_6) {
  } else {
    __pyx_t_1 = __pyx_t_6;
    goto __pyx_L30_bool_binop_done;
  }
  __pyx_t_6 = ((__pyx_v_stream_read_status != Z_BUF_ERROR) != 0);
  __pyx_t_1 = __pyx_t_6;
  __pyx_L30_bool_binop_done:;
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":462
 *         # Error
 *         if stream_read_status < 0 and stream_read_status != Z_BUF_ERROR:
 *             self._free_z_stream()             # <<<<<<<<<<<<<<
 *             raise StreamError('Not a valid GZip stream')
 * 
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_free_z_stream(__pyx_v_self);

    /* "fastwarc/stream_io.pyx":463
 *         if stream_read_status < 0 and stream_read_status != Z_BUF_ERROR:
 *             self._free_z_stream()
 *             raise StreamError('Not a valid GZip stream')             # <<<<<<<<<<<<<<
 * 
 *         # Member end
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 463, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_Not_a_valid_GZip_stream) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_Not_a_valid_GZip_stream);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 463, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 463, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":461
 * 
 *         # Error
 *         if stream_read_status < 0 and stream_read_status != Z_BUF_ERROR:             # <<<<<<<<<<<<<<
 *             self._free_z_stream()
 *             raise StreamError('Not a valid GZip stream')
 */
  }

  /* "fastwarc/stream_io.pyx":466
 * 
 *         # Member end
 *         if stream_read_status == Z_STREAM_END:             # <<<<<<<<<<<<<<
 *             inflateReset(&self.zst)
 * 
 */
  __pyx_t_1 = ((__pyx_v_stream_read_status == Z_STREAM_END) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":467
 *         # Member end
 *         if stream_read_status == Z_STREAM_END:
 *             inflateReset(&self.zst)             # <<<<<<<<<<<<<<
 * 
 *         return size - self.zst.avail_out
 */
    (void)(inflateReset((&__pyx_v_self->zst)));

    /* "fastwarc/stream_io.pyx":466
 * 
 *         # Member end
 *         if stream_read_status == Z_STREAM_END:             # <<<<<<<<<<<<<<
 *             inflateReset(&self.zst)
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":469
 *             inflateReset(&self.zst)
 * 
 *         return size - self.zst.avail_out             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 */
  __pyx_r = (__pyx_v_size - __pyx_v_self->zst.avail_out);
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":426
 *         return True
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             raise StreamError('Compression in progress.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.GZipStream.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":471
 *         return size - self.zst.avail_out
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             raise StreamError('Decompression in progress')
 */

static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_write(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size) {
  size_t __pyx_v_written;
  size_t __pyx_v_bound;
  int __pyx_v_status;
  size_t __pyx_v_written_so_far;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned long __pyx_t_5;
  unsigned long __pyx_t_6;
  unsigned long __pyx_t_7;
  int __pyx_t_8;
  size_t __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write", 0);

  /* "fastwarc/stream_io.pyx":472
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:             # <<<<<<<<<<<<<<
 *             raise StreamError('Decompression in progress')
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->stream_state == DECOMPRESSING) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":473
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             raise StreamError('Decompression in progress')             # <<<<<<<<<<<<<<
 * 
 *         if not self.stream_state:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 473, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_Decompression_in_progress) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_Decompression_in_progress);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 473, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 473, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":472
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:             # <<<<<<<<<<<<<<
 *             raise StreamError('Decompression in progress')
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":475
 *             raise StreamError('Decompression in progress')
 * 
 *         if not self.stream_state:             # <<<<<<<<<<<<<<
 *             self._init_z_stream(True)
 * 
 */
  __pyx_t_1 = ((!(__pyx_v_self->stream_state != 0)) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":476
 * 
 *         if not self.stream_state:
 *             self._init_z_stream(True)             # <<<<<<<<<<<<<<
 * 
 *         self.zst.next_in = <Bytef*>data
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_init_z_stream(__pyx_v_self, 1);

    /* "fastwarc/stream_io.pyx":475
 *             raise StreamError('Decompression in progress')
 * 
 *         if not self.stream_state:             # <<<<<<<<<<<<<<
 *             self._init_z_stream(True)
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":478
 *             self._init_z_stream(True)
 * 
 *         self.zst.next_in = <Bytef*>data             # <<<<<<<<<<<<<<
 *         self.zst.avail_in = <unsigned int>size
 * 
 */
  __pyx_v_self->zst.next_in = ((Bytef *)__pyx_v_data);

  /* "fastwarc/stream_io.pyx":479
 * 
 *         self.zst.next_in = <Bytef*>data
 *         self.zst.avail_in = <unsigned int>size             # <<<<<<<<<<<<<<
 * 
 *         self.begin_member()
 */
  __pyx_v_self->zst.avail_in = ((unsigned int)__pyx_v_size);

  /* "fastwarc/stream_io.pyx":481
 *         self.zst.avail_in = <unsigned int>size
 * 
 *         self.begin_member()             # <<<<<<<<<<<<<<
 *         cdef size_t written = 0
 *         cdef size_t bound = max(8192u, deflateBound(&self.zst, <unsigned long>size))
 */
  (void)(((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.begin_member(((struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *)__pyx_v_self)));

  /* "fastwarc/stream_io.pyx":482
 * 
 *         self.begin_member()
 *         cdef size_t written = 0             # <<<<<<<<<<<<<<
 *         cdef size_t bound = max(8192u, deflateBound(&self.zst, <unsigned long>size))
 *         if self.working_buf.size() < bound:
 */
  __pyx_v_written = 0;

  /* "fastwarc/stream_io.pyx":483
 *         self.begin_member()
 *         cdef size_t written = 0
 *         cdef size_t bound = max(8192u, deflateBound(&self.zst, <unsigned long>size))             # <<<<<<<<<<<<<<
 *         if self.working_buf.size() < bound:
 *             self.working_buf.resize(bound)
 */
  __pyx_t_5 = deflateBound((&__pyx_v_self->zst), ((unsigned long)__pyx_v_size));
  __pyx_t_6 = 8192U;
  if (((__pyx_t_5 > __pyx_t_6) != 0)) {
    __pyx_t_7 = __pyx_t_5;
  } else {
    __pyx_t_7 = __pyx_t_6;
  }
  __pyx_v_bound = __pyx_t_7;

  /* "fastwarc/stream_io.pyx":484
 *         cdef size_t written = 0
 *         cdef size_t bound = max(8192u, deflateBound(&self.zst, <unsigned long>size))
 *         if self.working_buf.size() < bound:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(bound)
 *         self.zst.next_out = <Bytef*>self.working_buf.data()
 */
  __pyx_t_1 = ((__pyx_v_self->working_buf.size() < __pyx_v_bound) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":485
 *         cdef size_t bound = max(8192u, deflateBound(&self.zst, <unsigned long>size))
 *         if self.working_buf.size() < bound:
 *             self.working_buf.resize(bound)             # <<<<<<<<<<<<<<
 *         self.zst.next_out = <Bytef*>self.working_buf.data()
 *         self.zst.avail_out = <unsigned int>self.working_buf.size()
 */
    try {
      __pyx_v_self->working_buf.resize(__pyx_v_bound);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 485, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":484
 *         cdef size_t written = 0
 *         cdef size_t bound = max(8192u, deflateBound(&self.zst, <unsigned long>size))
 *         if self.working_buf.size() < bound:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(bound)
 *         self.zst.next_out = <Bytef*>self.working_buf.data()
 */
  }

  /* "fastwarc/stream_io.pyx":486
 *         if self.working_buf.size() < bound:
 *             self.working_buf.resize(bound)
 *         self.zst.next_out = <Bytef*>self.working_buf.data()             # <<<<<<<<<<<<<<
 *         self.zst.avail_out = <unsigned int>self.working_buf.size()
 * 
 */
  __pyx_v_self->zst.next_out = ((Bytef *)__pyx_v_self->working_buf.data());

  /* "fastwarc/stream_io.pyx":487
 *             self.working_buf.resize(bound)
 *         self.zst.next_out = <Bytef*>self.working_buf.data()
 *         self.zst.avail_out = <unsigned int>self.working_buf.size()             # <<<<<<<<<<<<<<
 * 
 *         cdef int status = Z_OK
 */
  __pyx_v_self->zst.avail_out = ((unsigned int)__pyx_v_self->working_buf.size());

  /* "fastwarc/stream_io.pyx":489
 *         self.zst.avail_out = <unsigned int>self.working_buf.size()
 * 
 *         cdef int status = Z_OK             # <<<<<<<<<<<<<<
 *         cdef size_t written_so_far = self.zst.total_out
 * 
 */
  __pyx_v_status = Z_OK;

  /* "fastwarc/stream_io.pyx":490
 * 
 *         cdef int status = Z_OK
 *         cdef size_t written_so_far = self.zst.total_out             # <<<<<<<<<<<<<<
 * 
 *         while self.zst.avail_in > 0 and status == Z_OK:
 */
  __pyx_t_7 = __pyx_v_self->zst.total_out;
  __pyx_v_written_so_far = __pyx_t_7;

  /* "fastwarc/stream_io.pyx":492
 *         cdef size_t written_so_far = self.zst.total_out
 * 
 *         while self.zst.avail_in > 0 and status == Z_OK:             # <<<<<<<<<<<<<<
 *             status = deflate(&self.zst, Z_NO_FLUSH)
 *             if self.zst.avail_in > 0 and self.zst.avail_out == 0:
 */
  while (1) {
    __pyx_t_8 = ((__pyx_v_self->zst.avail_in > 0) != 0);
    if (__pyx_t_8) {
    } else {
      __pyx_t_1 = __pyx_t_8;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_t_8 = ((__pyx_v_status == Z_OK) != 0);
    __pyx_t_1 = __pyx_t_8;
    __pyx_L8_bool_binop_done:;
    if (!__pyx_t_1) break;

    /* "fastwarc/stream_io.pyx":493
 * 
 *         while self.zst.avail_in > 0 and status == Z_OK:
 *             status = deflate(&self.zst, Z_NO_FLUSH)             # <<<<<<<<<<<<<<
 *             if self.zst.avail_in > 0 and self.zst.avail_out == 0:
 *                 # Out buffer fully filled, but in buffer still holding data
 */
    __pyx_v_status = deflate((&__pyx_v_self->zst), Z_NO_FLUSH);

    /* "fastwarc/stream_io.pyx":494
 *         while self.zst.avail_in > 0 and status == Z_OK:
 *             status = deflate(&self.zst, Z_NO_FLUSH)
 *             if self.zst.avail_in > 0 and self.zst.avail_out == 0:             # <<<<<<<<<<<<<<
 *                 # Out buffer fully filled, but in buffer still holding data
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)
 */
    __pyx_t_8 = ((__pyx_v_self->zst.avail_in > 0) != 0);
    if (__pyx_t_8) {
    } else {
      __pyx_t_1 = __pyx_t_8;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_8 = ((__pyx_v_self->zst.avail_out == 0) != 0);
    __pyx_t_1 = __pyx_t_8;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":496
 *             if self.zst.avail_in > 0 and self.zst.avail_out == 0:
 *                 # Out buffer fully filled, but in buffer still holding data
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)             # <<<<<<<<<<<<<<
 *                 self.zst.next_out = <Bytef*>self.working_buf.data() + self.working_buf.size() - 4096u
 *                 self.zst.avail_out = 4096u
 */
      try {
        __pyx_v_self->working_buf.resize((__pyx_v_self->working_buf.size() + 4096U));
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(1, 496, __pyx_L1_error)
      }

      /* "fastwarc/stream_io.pyx":497
 *                 # Out buffer fully filled, but in buffer still holding data
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)
 *                 self.zst.next_out = <Bytef*>self.working_buf.data() + self.working_buf.size() - 4096u             # <<<<<<<<<<<<<<
 *                 self.zst.avail_out = 4096u
 * 
 */
      __pyx_v_self->zst.next_out = ((((Bytef *)__pyx_v_self->working_buf.data()) + __pyx_v_self->working_buf.size()) - 4096U);

      /* "fastwarc/stream_io.pyx":498
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)
 *                 self.zst.next_out = <Bytef*>self.working_buf.data() + self.working_buf.size() - 4096u
 *                 self.zst.avail_out = 4096u             # <<<<<<<<<<<<<<
 * 
 *         written += self.zst.total_out - written_so_far
 */
      __pyx_v_self->zst.avail_out = 4096U;

      /* "fastwarc/stream_io.pyx":494
 *         while self.zst.avail_in > 0 and status == Z_OK:
 *             status = deflate(&self.zst, Z_NO_FLUSH)
 *             if self.zst.avail_in > 0 and self.zst.avail_out == 0:             # <<<<<<<<<<<<<<
 *                 # Out buffer fully filled, but in buffer still holding data
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)
 */
    }
  }

  /* "fastwarc/stream_io.pyx":500
 *                 self.zst.avail_out = 4096u
 * 
 *         written += self.zst.total_out - written_so_far             # <<<<<<<<<<<<<<
 *         self.stream_pos += written
 *         if written == 0:
 */
  __pyx_v_written = (__pyx_v_written + (__pyx_v_self->zst.total_out - __pyx_v_written_so_far));

  /* "fastwarc/stream_io.pyx":501
 * 
 *         written += self.zst.total_out - written_so_far
 *         self.stream_pos += written             # <<<<<<<<<<<<<<
 *         if written == 0:
 *             return 0
 */
  __pyx_v_self->stream_pos = (__pyx_v_self->stream_pos + __pyx_v_written);

  /* "fastwarc/stream_io.pyx":502
 *         written += self.zst.total_out - written_so_far
 *         self.stream_pos += written
 *         if written == 0:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_1 = ((__pyx_v_written == 0) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":503
 *         self.stream_pos += written
 *         if written == 0:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         return self.raw_stream.write(self.working_buf.data(), written)
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":502
 *         written += self.zst.total_out - written_so_far
 *         self.stream_pos += written
 *         if written == 0:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":505
 *             return 0
 * 
 *         return self.raw_stream.write(self.working_buf.data(), written)             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t begin_member(self):
 */
  __pyx_t_9 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, __pyx_v_self->working_buf.data(), __pyx_v_written); if (unlikely(__pyx_t_9 == ((size_t)-1L))) __PYX_ERR(1, 505, __pyx_L1_error)
  __pyx_r = __pyx_t_9;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":471
 *         return size - self.zst.avail_out
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             raise StreamError('Decompression in progress')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.GZipStream.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":507
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 *     cdef size_t begin_member(self):             # <<<<<<<<<<<<<<
 *         self.member_started = True
 *         return 0
 */

static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_begin_member(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("begin_member", 0);

  /* "fastwarc/stream_io.pyx":508
 * 
 *     cdef size_t begin_member(self):
 *         self.member_started = True             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
  __pyx_v_self->member_started = 1;

  /* "fastwarc/stream_io.pyx":509
 *     cdef size_t begin_member(self):
 *         self.member_started = True
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t end_member(self):
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":507
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 *     cdef size_t begin_member(self):             # <<<<<<<<<<<<<<
 *         self.member_started = True
 *         return 0
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":511
 *         return 0
 * 
 *     cdef size_t end_member(self):             # <<<<<<<<<<<<<<
 *         if not self.member_started:
 *             return 0
 */

static size_t __pyx_f_8fastwarc_9stream_io_10GZipStream_end_member(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self) {
  size_t __pyx_v_written_so_far;
  int __pyx_v_status;
  size_t __pyx_v_written;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  unsigned long __pyx_t_2;
  int __pyx_t_3;
  size_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("end_member", 0);

  /* "fastwarc/stream_io.pyx":512
 * 
 *     cdef size_t end_member(self):
 *         if not self.member_started:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_1 = ((!(__pyx_v_self->member_started != 0)) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":513
 *     cdef size_t end_member(self):
 *         if not self.member_started:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         self.zst.avail_in = 0u
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":512
 * 
 *     cdef size_t end_member(self):
 *         if not self.member_started:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":515
 *             return 0
 * 
 *         self.zst.avail_in = 0u             # <<<<<<<<<<<<<<
 *         self.zst.next_in = NULL
 *         self.zst.next_out = <Bytef*>self.working_buf.data()
 */
  __pyx_v_self->zst.avail_in = 0U;

  /* "fastwarc/stream_io.pyx":516
 * 
 *         self.zst.avail_in = 0u
 *         self.zst.next_in = NULL             # <<<<<<<<<<<<<<
 *         self.zst.next_out = <Bytef*>self.working_buf.data()
 *         self.zst.avail_out = <unsigned int>self.working_buf.size()
 */
  __pyx_v_self->zst.next_in = NULL;

  /* "fastwarc/stream_io.pyx":517
 *         self.zst.avail_in = 0u
 *         self.zst.next_in = NULL
 *         self.zst.next_out = <Bytef*>self.working_buf.data()             # <<<<<<<<<<<<<<
 *         self.zst.avail_out = <unsigned int>self.working_buf.size()
 * 
 */
  __pyx_v_self->zst.next_out = ((Bytef *)__pyx_v_self->working_buf.data());

  /* "fastwarc/stream_io.pyx":518
 *         self.zst.next_in = NULL
 *         self.zst.next_out = <Bytef*>self.working_buf.data()
 *         self.zst.avail_out = <unsigned int>self.working_buf.size()             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t written_so_far = self.zst.total_out
 */
  __pyx_v_self->zst.avail_out = ((unsigned int)__pyx_v_self->working_buf.size());

  /* "fastwarc/stream_io.pyx":520
 *         self.zst.avail_out = <unsigned int>self.working_buf.size()
 * 
 *         cdef size_t written_so_far = self.zst.total_out             # <<<<<<<<<<<<<<
 *         cdef int status = deflate(&self.zst, Z_FINISH)
 *         while status == Z_OK or status == Z_BUF_ERROR:
 */
  __pyx_t_2 = __pyx_v_self->zst.total_out;
  __pyx_v_written_so_far = __pyx_t_2;

  /* "fastwarc/stream_io.pyx":521
 * 
 *         cdef size_t written_so_far = self.zst.total_out
 *         cdef int status = deflate(&self.zst, Z_FINISH)             # <<<<<<<<<<<<<<
 *         while status == Z_OK or status == Z_BUF_ERROR:
 *             if self.zst.avail_out == 0:
 */
  __pyx_v_status = deflate((&__pyx_v_self->zst), Z_FINISH);

  /* "fastwarc/stream_io.pyx":522
 *         cdef size_t written_so_far = self.zst.total_out
 *         cdef int status = deflate(&self.zst, Z_FINISH)
 *         while status == Z_OK or status == Z_BUF_ERROR:             # <<<<<<<<<<<<<<
 *             if self.zst.avail_out == 0:
 *                 # Need larger output buffer (unlikely to ever happen at this point)
 */
  while (1) {
    __pyx_t_3 = ((__pyx_v_status == Z_OK) != 0);
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_status == Z_BUF_ERROR) != 0);
    __pyx_t_1 = __pyx_t_3;
    __pyx_L6_bool_binop_done:;
    if (!__pyx_t_1) break;

    /* "fastwarc/stream_io.pyx":523
 *         cdef int status = deflate(&self.zst, Z_FINISH)
 *         while status == Z_OK or status == Z_BUF_ERROR:
 *             if self.zst.avail_out == 0:             # <<<<<<<<<<<<<<
 *                 # Need larger output buffer (unlikely to ever happen at this point)
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)
 */
    __pyx_t_1 = ((__pyx_v_self->zst.avail_out == 0) != 0);
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":525
 *             if self.zst.avail_out == 0:
 *                 # Need larger output buffer (unlikely to ever happen at this point)
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)             # <<<<<<<<<<<<<<
 *                 self.zst.next_out = <Bytef*>self.working_buf.data() + self.working_buf.size() - 4096u
 *                 self.zst.avail_out = 4096u
 */
      try {
        __pyx_v_self->working_buf.resize((__pyx_v_self->working_buf.size() + 4096U));
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(1, 525, __pyx_L1_error)
      }

      /* "fastwarc/stream_io.pyx":526
 *                 # Need larger output buffer (unlikely to ever happen at this point)
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)
 *                 self.zst.next_out = <Bytef*>self.working_buf.data() + self.working_buf.size() - 4096u             # <<<<<<<<<<<<<<
 *                 self.zst.avail_out = 4096u
 *             status = deflate(&self.zst, Z_FINISH)
 */
      __pyx_v_self->zst.next_out = ((((Bytef *)__pyx_v_self->working_buf.data()) + __pyx_v_self->working_buf.size()) - 4096U);

      /* "fastwarc/stream_io.pyx":527
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)
 *                 self.zst.next_out = <Bytef*>self.working_buf.data() + self.working_buf.size() - 4096u
 *                 self.zst.avail_out = 4096u             # <<<<<<<<<<<<<<
 *             status = deflate(&self.zst, Z_FINISH)
 * 
 */
      __pyx_v_self->zst.avail_out = 4096U;

      /* "fastwarc/stream_io.pyx":523
 *         cdef int status = deflate(&self.zst, Z_FINISH)
 *         while status == Z_OK or status == Z_BUF_ERROR:
 *             if self.zst.avail_out == 0:             # <<<<<<<<<<<<<<
 *                 # Need larger output buffer (unlikely to ever happen at this point)
 *                 self.working_buf.resize(self.working_buf.size() + 4096u)
 */
    }

    /* "fastwarc/stream_io.pyx":528
 *                 self.zst.next_out = <Bytef*>self.working_buf.data() + self.working_buf.size() - 4096u
 *                 self.zst.avail_out = 4096u
 *             status = deflate(&self.zst, Z_FINISH)             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t written = self.zst.total_out - written_so_far
 */
    __pyx_v_status = deflate((&__pyx_v_self->zst), Z_FINISH);
  }

  /* "fastwarc/stream_io.pyx":530
 *             status = deflate(&self.zst, Z_FINISH)
 * 
 *         cdef size_t written = self.zst.total_out - written_so_far             # <<<<<<<<<<<<<<
 *         deflateReset(&self.zst)
 *         self.stream_pos += written
 */
  __pyx_v_written = (__pyx_v_self->zst.total_out - __pyx_v_written_so_far);

  /* "fastwarc/stream_io.pyx":531
 * 
 *         cdef size_t written = self.zst.total_out - written_so_far
 *         deflateReset(&self.zst)             # <<<<<<<<<<<<<<
 *         self.stream_pos += written
 *         self.member_started = False
 */
  (void)(deflateReset((&__pyx_v_self->zst)));

  /* "fastwarc/stream_io.pyx":532
 *         cdef size_t written = self.zst.total_out - written_so_far
 *         deflateReset(&self.zst)
 *         self.stream_pos += written             # <<<<<<<<<<<<<<
 *         self.member_started = False
 * 
 */
  __pyx_v_self->stream_pos = (__pyx_v_self->stream_pos + __pyx_v_written);

  /* "fastwarc/stream_io.pyx":533
 *         deflateReset(&self.zst)
 *         self.stream_pos += written
 *         self.member_started = False             # <<<<<<<<<<<<<<
 * 
 *         if written == 0:
 */
  __pyx_v_self->member_started = 0;

  /* "fastwarc/stream_io.pyx":535
 *         self.member_started = False
 * 
 *         if written == 0:             # <<<<<<<<<<<<<<
 *             return 0
 *         return self.raw_stream.write(self.working_buf.data(), written)
 */
  __pyx_t_1 = ((__pyx_v_written == 0) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":536
 * 
 *         if written == 0:
 *             return 0             # <<<<<<<<<<<<<<
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":535
 *         self.member_started = False
 * 
 *         if written == 0:             # <<<<<<<<<<<<<<
 *             return 0
 *         return self.raw_stream.write(self.working_buf.data(), written)
 */
  }

  /* "fastwarc/stream_io.pyx":537
 *         if written == 0:
 *             return 0
 *         return self.raw_stream.write(self.working_buf.data(), written)             # <<<<<<<<<<<<<<
 * 
 *     cdef void flush(self) except *:
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, __pyx_v_self->working_buf.data(), __pyx_v_written); if (unlikely(__pyx_t_4 == ((size_t)-1L))) __PYX_ERR(1, 537, __pyx_L1_error)
  __pyx_r = __pyx_t_4;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":511
 *         return 0
 * 
 *     cdef size_t end_member(self):             # <<<<<<<<<<<<<<
 *         if not self.member_started:
 *             return 0
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("fastwarc.stream_io.GZipStream.end_member", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":539
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 *     cdef void flush(self) except *:             # <<<<<<<<<<<<<<
 *         self.end_member()
 *         self.raw_stream.flush()
 */

static void __pyx_f_8fastwarc_9stream_io_10GZipStream_flush(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("flush", 0);

  /* "fastwarc/stream_io.pyx":540
 * 
 *     cdef void flush(self) except *:
 *         self.end_member()             # <<<<<<<<<<<<<<
 *         self.raw_stream.flush()
 * 
 */
  (void)(((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.end_member(((struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *)__pyx_v_self)));

  /* "fastwarc/stream_io.pyx":541
 *     cdef void flush(self) except *:
 *         self.end_member()
 *         self.raw_stream.flush()             # <<<<<<<<<<<<<<
 * 
 *     cdef void close(self) except *:
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->flush(__pyx_v_self->raw_stream); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 541, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":539
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 *     cdef void flush(self) except *:             # <<<<<<<<<<<<<<
 *         self.end_member()
 *         self.raw_stream.flush()
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.GZipStream.flush", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":543
 *         self.raw_stream.flush()
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         self.end_member()
 *         self._free_z_stream()
 */

static void __pyx_f_8fastwarc_9stream_io_10GZipStream_close(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close", 0);

  /* "fastwarc/stream_io.pyx":544
 * 
 *     cdef void close(self) except *:
 *         self.end_member()             # <<<<<<<<<<<<<<
 *         self._free_z_stream()
 * 
 */
  (void)(((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.end_member(((struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *)__pyx_v_self)));

  /* "fastwarc/stream_io.pyx":545
 *     cdef void close(self) except *:
 *         self.end_member()
 *         self._free_z_stream()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_free_z_stream(__pyx_v_self);

  /* "fastwarc/stream_io.pyx":543
 *         self.raw_stream.flush()
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         self.end_member()
 *         self._free_z_stream()
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":563
 *     """
 * 
 *     def __init__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_9LZ4Stream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_9LZ4Stream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_9LZ4Stream___init__(((struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_9LZ4Stream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":566
 *         pass
 * 
 *     def __cinit__(self, raw_stream, compression_level=LZ4HC_CLEVEL_MAX, favor_dec_speed=True):             # <<<<<<<<<<<<<<
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.cctx = NULL
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_9LZ4Stream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_9LZ4Stream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_raw_stream = 0;
  PyObject *__pyx_v_compression_level = 0;
  PyObject *__pyx_v_favor_dec_speed = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_raw_stream,&__pyx_n_s_compression_level,&__pyx_n_s_favor_dec_speed,0};
    PyObject* values[3] = {0,0,0};
    values[1] = __pyx_k__3;
    values[2] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raw_stream)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_compression_level);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_favor_dec_speed);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 566, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_raw_stream = values[0];
    __pyx_v_compression_level = values[1];
    __pyx_v_favor_dec_speed = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 566, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.LZ4Stream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_9LZ4Stream_2__cinit__(((struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self), __pyx_v_raw_stream, __pyx_v_compression_level, __pyx_v_favor_dec_speed);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_9LZ4Stream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, PyObject *__pyx_v_raw_stream, PyObject *__pyx_v_compression_level, PyObject *__pyx_v_favor_dec_speed) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  std::string __pyx_t_2;
  int __pyx_t_3;
  unsigned int __pyx_t_4;
  size_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "fastwarc/stream_io.pyx":567
 * 
 *     def __cinit__(self, raw_stream, compression_level=LZ4HC_CLEVEL_MAX, favor_dec_speed=True):
 *         self.raw_stream = wrap_stream(raw_stream)             # <<<<<<<<<<<<<<
 *         self.cctx = NULL
 *         self.dctx = NULL
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_8fastwarc_9stream_io_wrap_stream(__pyx_v_raw_stream, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->raw_stream);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->raw_stream));
  __pyx_v_self->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":568
 *     def __cinit__(self, raw_stream, compression_level=LZ4HC_CLEVEL_MAX, favor_dec_speed=True):
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.cctx = NULL             # <<<<<<<<<<<<<<
 *         self.dctx = NULL
 *         self.working_buf = string()
 */
  __pyx_v_self->cctx = NULL;

  /* "fastwarc/stream_io.pyx":569
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.cctx = NULL
 *         self.dctx = NULL             # <<<<<<<<<<<<<<
 *         self.working_buf = string()
 *         self.working_buf_read = 0u
 */
  __pyx_v_self->dctx = NULL;

  /* "fastwarc/stream_io.pyx":570
 *         self.cctx = NULL
 *         self.dctx = NULL
 *         self.working_buf = string()             # <<<<<<<<<<<<<<
 *         self.working_buf_read = 0u
 *         self.working_buf_filled = 0u
 */
  try {
    __pyx_t_2 = std::string();
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 570, __pyx_L1_error)
  }
  __pyx_v_self->working_buf = __pyx_t_2;

  /* "fastwarc/stream_io.pyx":571
 *         self.dctx = NULL
 *         self.working_buf = string()
 *         self.working_buf_read = 0u             # <<<<<<<<<<<<<<
 *         self.working_buf_filled = 0u
 *         self.frame_started = False
 */
  __pyx_v_self->working_buf_read = 0U;

  /* "fastwarc/stream_io.pyx":572
 *         self.working_buf = string()
 *         self.working_buf_read = 0u
 *         self.working_buf_filled = 0u             # <<<<<<<<<<<<<<
 *         self.frame_started = False
 *         self.prefs.compressionLevel = compression_level
 */
  __pyx_v_self->working_buf_filled = 0U;

  /* "fastwarc/stream_io.pyx":573
 *         self.working_buf_read = 0u
 *         self.working_buf_filled = 0u
 *         self.frame_started = False             # <<<<<<<<<<<<<<
 *         self.prefs.compressionLevel = compression_level
 *         self.prefs.favorDecSpeed = favor_dec_speed
 */
  __pyx_v_self->frame_started = 0;

  /* "fastwarc/stream_io.pyx":574
 *         self.working_buf_filled = 0u
 *         self.frame_started = False
 *         self.prefs.compressionLevel = compression_level             # <<<<<<<<<<<<<<
 *         self.prefs.favorDecSpeed = favor_dec_speed
 *         self.stream_pos = self.raw_stream.tell()
 */
  __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_compression_level); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 574, __pyx_L1_error)
  __pyx_v_self->prefs.compressionLevel = __pyx_t_3;

  /* "fastwarc/stream_io.pyx":575
 *         self.frame_started = False
 *         self.prefs.compressionLevel = compression_level
 *         self.prefs.favorDecSpeed = favor_dec_speed             # <<<<<<<<<<<<<<
 *         self.stream_pos = self.raw_stream.tell()
 * 
 */
  __pyx_t_4 = __Pyx_PyInt_As_unsigned_int(__pyx_v_favor_dec_speed); if (unlikely((__pyx_t_4 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(1, 575, __pyx_L1_error)
  __pyx_v_self->prefs.favorDecSpeed = __pyx_t_4;

  /* "fastwarc/stream_io.pyx":576
 *         self.prefs.compressionLevel = compression_level
 *         self.prefs.favorDecSpeed = favor_dec_speed
 *         self.stream_pos = self.raw_stream.tell()             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_t_5 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->tell(__pyx_v_self->raw_stream); if (unlikely(__pyx_t_5 == ((size_t)-1L))) __PYX_ERR(1, 576, __pyx_L1_error)
  __pyx_v_self->stream_pos = __pyx_t_5;

  /* "fastwarc/stream_io.pyx":566
 *         pass
 * 
 *     def __cinit__(self, raw_stream, compression_level=LZ4HC_CLEVEL_MAX, favor_dec_speed=True):             # <<<<<<<<<<<<<<
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.cctx = NULL
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("fastwarc.stream_io.LZ4Stream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":578
 *         self.stream_pos = self.raw_stream.tell()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

/* Python wrapper */
static void __pyx_pw_8fastwarc_9stream_io_9LZ4Stream_5__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_8fastwarc_9stream_io_9LZ4Stream_5__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_8fastwarc_9stream_io_9LZ4Stream_4__dealloc__(((struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_8fastwarc_9stream_io_9LZ4Stream_4__dealloc__(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);

  /* "fastwarc/stream_io.pyx":579
 * 
 *     def __dealloc__(self):
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t tell(self) except -1:
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.close(((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_v_self)); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 579, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":578
 *         self.stream_pos = self.raw_stream.tell()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("fastwarc.stream_io.LZ4Stream.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":581
 *         self.close()
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         return self.stream_pos
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_tell(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("tell", 0);

  /* "fastwarc/stream_io.pyx":582
 * 
 *     cdef size_t tell(self) except -1:
 *         return self.stream_pos             # <<<<<<<<<<<<<<
 * 
 *     cdef void prepopulate(self, const string& initial_data):
 */
  __pyx_r = __pyx_v_self->stream_pos;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":581
 *         self.close()
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         return self.stream_pos
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":584
 *         return self.stream_pos
 * 
 *     cdef void prepopulate(self, const string& initial_data):             # <<<<<<<<<<<<<<
 *         """
 *         Fill internal working buffer with initial data.
 */

static void __pyx_f_8fastwarc_9stream_io_9LZ4Stream_prepopulate(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, std::string const &__pyx_v_initial_data) {
  __Pyx_RefNannyDeclarations
  size_t __pyx_t_1;
  size_t __pyx_t_2;
  unsigned long __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("prepopulate", 0);

  /* "fastwarc/stream_io.pyx":592
 *         :param initial_data: data to pre-populate
 *         """
 *         self.working_buf.append(initial_data)             # <<<<<<<<<<<<<<
 *         self.working_buf_filled += <unsigned int>initial_data.size()
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)
 */
  try {
    __pyx_v_self->working_buf.append(__pyx_v_initial_data);
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 592, __pyx_L1_error)
  }

  /* "fastwarc/stream_io.pyx":593
 *         """
 *         self.working_buf.append(initial_data)
 *         self.working_buf_filled += <unsigned int>initial_data.size()             # <<<<<<<<<<<<<<
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)
 * 
 */
  __pyx_v_self->working_buf_filled = (__pyx_v_self->working_buf_filled + ((unsigned int)__pyx_v_initial_data.size()));

  /* "fastwarc/stream_io.pyx":594
 *         self.working_buf.append(initial_data)
 *         self.working_buf_filled += <unsigned int>initial_data.size()
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->tell(__pyx_v_self->raw_stream); if (unlikely(__pyx_t_1 == ((size_t)-1L))) __PYX_ERR(1, 594, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_1 - __pyx_v_self->working_buf_filled);
  __pyx_t_3 = 0U;
  if (((__pyx_t_2 > __pyx_t_3) != 0)) {
    __pyx_t_1 = __pyx_t_2;
  } else {
    __pyx_t_1 = __pyx_t_3;
  }
  __pyx_v_self->stream_pos = __pyx_t_1;

  /* "fastwarc/stream_io.pyx":584
 *         return self.stream_pos
 * 
 *     cdef void prepopulate(self, const string& initial_data):             # <<<<<<<<<<<<<<
 *         """
 *         Fill internal working buffer with initial data.
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("fastwarc.stream_io.LZ4Stream.prepopulate", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":596
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.cctx != NULL:
 *             raise StreamError('Compression in progress.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_read(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size) {
  size_t __pyx_v_ret;
  size_t __pyx_v_bytes_in;
  size_t __pyx_v_bytes_out;
  size_t __pyx_v_out_buf_consumed;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  size_t __pyx_t_6;
  char const *__pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("read", 0);

  /* "fastwarc/stream_io.pyx":597
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.cctx != NULL:             # <<<<<<<<<<<<<<
 *             raise StreamError('Compression in progress.')
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->cctx != NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":598
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.cctx != NULL:
 *             raise StreamError('Compression in progress.')             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t ret
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 598, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_Compression_in_progress) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_Compression_in_progress);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 598, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 598, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":597
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.cctx != NULL:             # <<<<<<<<<<<<<<
 *             raise StreamError('Compression in progress.')
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":601
 * 
 *         cdef size_t ret
 *         cdef size_t bytes_in = 0, bytes_out = 0             # <<<<<<<<<<<<<<
 *         cdef size_t out_buf_consumed = 0
 * 
 */
  __pyx_v_bytes_in = 0;
  __pyx_v_bytes_out = 0;

  /* "fastwarc/stream_io.pyx":602
 *         cdef size_t ret
 *         cdef size_t bytes_in = 0, bytes_out = 0
 *         cdef size_t out_buf_consumed = 0             # <<<<<<<<<<<<<<
 * 
 *         if self.dctx == NULL:
 */
  __pyx_v_out_buf_consumed = 0;

  /* "fastwarc/stream_io.pyx":604
 *         cdef size_t out_buf_consumed = 0
 * 
 *         if self.dctx == NULL:             # <<<<<<<<<<<<<<
 *             LZ4F_createDecompressionContext(&self.dctx, LZ4F_VERSION)
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->dctx == NULL) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":605
 * 
 *         if self.dctx == NULL:
 *             LZ4F_createDecompressionContext(&self.dctx, LZ4F_VERSION)             # <<<<<<<<<<<<<<
 * 
 *         if self.working_buf.size() < size:
 */
    (void)(LZ4F_createDecompressionContext((&__pyx_v_self->dctx), LZ4F_VERSION));

    /* "fastwarc/stream_io.pyx":604
 *         cdef size_t out_buf_consumed = 0
 * 
 *         if self.dctx == NULL:             # <<<<<<<<<<<<<<
 *             LZ4F_createDecompressionContext(&self.dctx, LZ4F_VERSION)
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":607
 *             LZ4F_createDecompressionContext(&self.dctx, LZ4F_VERSION)
 * 
 *         if self.working_buf.size() < size:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(size)
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->working_buf.size() < __pyx_v_size) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":608
 * 
 *         if self.working_buf.size() < size:
 *             self.working_buf.resize(size)             # <<<<<<<<<<<<<<
 * 
 *         while True:
 */
    try {
      __pyx_v_self->working_buf.resize(__pyx_v_size);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 608, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":607
 *             LZ4F_createDecompressionContext(&self.dctx, LZ4F_VERSION)
 * 
 *         if self.working_buf.size() < size:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(size)
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":610
 *             self.working_buf.resize(size)
 * 
 *         while True:             # <<<<<<<<<<<<<<
 *             if self.working_buf_filled == 0 or self.working_buf_read == self.working_buf_filled:
 *                 self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)
 */
  while (1) {

    /* "fastwarc/stream_io.pyx":611
 * 
 *         while True:
 *             if self.working_buf_filled == 0 or self.working_buf_read == self.working_buf_filled:             # <<<<<<<<<<<<<<
 *                 self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)
 *                 self.working_buf_read = 0
 */
    __pyx_t_5 = ((__pyx_v_self->working_buf_filled == 0) != 0);
    if (!__pyx_t_5) {
    } else {
      __pyx_t_1 = __pyx_t_5;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_5 = ((__pyx_v_self->working_buf_read == __pyx_v_self->working_buf_filled) != 0);
    __pyx_t_1 = __pyx_t_5;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":612
 *         while True:
 *             if self.working_buf_filled == 0 or self.working_buf_read == self.working_buf_filled:
 *                 self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)             # <<<<<<<<<<<<<<
 *                 self.working_buf_read = 0
 * 
 */
      __pyx_t_6 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->read(__pyx_v_self->raw_stream, __pyx_v_self->working_buf.data(), __pyx_v_size); if (unlikely(__pyx_t_6 == ((size_t)-1L))) __PYX_ERR(1, 612, __pyx_L1_error)
      __pyx_v_self->working_buf_filled = ((unsigned int)__pyx_t_6);

      /* "fastwarc/stream_io.pyx":613
 *             if self.working_buf_filled == 0 or self.working_buf_read == self.working_buf_filled:
 *                 self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)
 *                 self.working_buf_read = 0             # <<<<<<<<<<<<<<
 * 
 *                 if self.working_buf_filled == 0:
 */
      __pyx_v_self->working_buf_read = 0;

      /* "fastwarc/stream_io.pyx":615
 *                 self.working_buf_read = 0
 * 
 *                 if self.working_buf_filled == 0:             # <<<<<<<<<<<<<<
 *                     # EOF
 *                     self._free_ctx()
 */
      __pyx_t_1 = ((__pyx_v_self->working_buf_filled == 0) != 0);
      if (__pyx_t_1) {

        /* "fastwarc/stream_io.pyx":617
 *                 if self.working_buf_filled == 0:
 *                     # EOF
 *                     self._free_ctx()             # <<<<<<<<<<<<<<
 *                     return out_buf_consumed
 * 
 */
        ((struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_free_ctx(__pyx_v_self);

        /* "fastwarc/stream_io.pyx":618
 *                     # EOF
 *                     self._free_ctx()
 *                     return out_buf_consumed             # <<<<<<<<<<<<<<
 * 
 *             bytes_in = self.working_buf_filled - self.working_buf_read
 */
        __pyx_r = __pyx_v_out_buf_consumed;
        goto __pyx_L0;

        /* "fastwarc/stream_io.pyx":615
 *                 self.working_buf_read = 0
 * 
 *                 if self.working_buf_filled == 0:             # <<<<<<<<<<<<<<
 *                     # EOF
 *                     self._free_ctx()
 */
      }

      /* "fastwarc/stream_io.pyx":611
 * 
 *         while True:
 *             if self.working_buf_filled == 0 or self.working_buf_read == self.working_buf_filled:             # <<<<<<<<<<<<<<
 *                 self.working_buf_filled = <unsigned int>self.raw_stream.read(self.working_buf.data(), size)
 *                 self.working_buf_read = 0
 */
    }

    /* "fastwarc/stream_io.pyx":620
 *                     return out_buf_consumed
 * 
 *             bytes_in = self.working_buf_filled - self.working_buf_read             # <<<<<<<<<<<<<<
 *             bytes_out = size - out_buf_consumed
 *             ret = LZ4F_decompress(self.dctx, out + out_buf_consumed, &bytes_out,
 */
    __pyx_v_bytes_in = (__pyx_v_self->working_buf_filled - __pyx_v_self->working_buf_read);

    /* "fastwarc/stream_io.pyx":621
 * 
 *             bytes_in = self.working_buf_filled - self.working_buf_read
 *             bytes_out = size - out_buf_consumed             # <<<<<<<<<<<<<<
 *             ret = LZ4F_decompress(self.dctx, out + out_buf_consumed, &bytes_out,
 *                                   self.working_buf.data() + self.working_buf_read, &bytes_in, NULL)
 */
    __pyx_v_bytes_out = (__pyx_v_size - __pyx_v_out_buf_consumed);

    /* "fastwarc/stream_io.pyx":622
 *             bytes_in = self.working_buf_filled - self.working_buf_read
 *             bytes_out = size - out_buf_consumed
 *             ret = LZ4F_decompress(self.dctx, out + out_buf_consumed, &bytes_out,             # <<<<<<<<<<<<<<
 *                                   self.working_buf.data() + self.working_buf_read, &bytes_in, NULL)
 *             self.stream_pos += bytes_in
 */
    __pyx_v_ret = LZ4F_decompress(__pyx_v_self->dctx, (__pyx_v_out + __pyx_v_out_buf_consumed), (&__pyx_v_bytes_out), (__pyx_v_self->working_buf.data() + __pyx_v_self->working_buf_read), (&__pyx_v_bytes_in), NULL);

    /* "fastwarc/stream_io.pyx":624
 *             ret = LZ4F_decompress(self.dctx, out + out_buf_consumed, &bytes_out,
 *                                   self.working_buf.data() + self.working_buf_read, &bytes_in, NULL)
 *             self.stream_pos += bytes_in             # <<<<<<<<<<<<<<
 *             self.working_buf_read += bytes_in
 *             out_buf_consumed += bytes_out
 */
    __pyx_v_self->stream_pos = (__pyx_v_self->stream_pos + __pyx_v_bytes_in);

    /* "fastwarc/stream_io.pyx":625
 *                                   self.working_buf.data() + self.working_buf_read, &bytes_in, NULL)
 *             self.stream_pos += bytes_in
 *             self.working_buf_read += bytes_in             # <<<<<<<<<<<<<<
 *             out_buf_consumed += bytes_out
 * 
 */
    __pyx_v_self->working_buf_read = (__pyx_v_self->working_buf_read + __pyx_v_bytes_in);

    /* "fastwarc/stream_io.pyx":626
 *             self.stream_pos += bytes_in
 *             self.working_buf_read += bytes_in
 *             out_buf_consumed += bytes_out             # <<<<<<<<<<<<<<
 * 
 *             if ret == 0 or out_buf_consumed == size or LZ4F_isError(ret):
 */
    __pyx_v_out_buf_consumed = (__pyx_v_out_buf_consumed + __pyx_v_bytes_out);

    /* "fastwarc/stream_io.pyx":628
 *             out_buf_consumed += bytes_out
 * 
 *             if ret == 0 or out_buf_consumed == size or LZ4F_isError(ret):             # <<<<<<<<<<<<<<
 *                 break
 * 
 */
    __pyx_t_5 = ((__pyx_v_ret == 0) != 0);
    if (!__pyx_t_5) {
    } else {
      __pyx_t_1 = __pyx_t_5;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_5 = ((__pyx_v_out_buf_consumed == __pyx_v_size) != 0);
    if (!__pyx_t_5) {
    } else {
      __pyx_t_1 = __pyx_t_5;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_5 = (LZ4F_isError(__pyx_v_ret) != 0);
    __pyx_t_1 = __pyx_t_5;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":629
 * 
 *             if ret == 0 or out_buf_consumed == size or LZ4F_isError(ret):
 *                 break             # <<<<<<<<<<<<<<
 * 
 *         if LZ4F_isError(ret):
 */
      goto __pyx_L7_break;

      /* "fastwarc/stream_io.pyx":628
 *             out_buf_consumed += bytes_out
 * 
 *             if ret == 0 or out_buf_consumed == size or LZ4F_isError(ret):             # <<<<<<<<<<<<<<
 *                 break
 * 
 */
    }
  }
  __pyx_L7_break:;

  /* "fastwarc/stream_io.pyx":631
 *                 break
 * 
 *         if LZ4F_isError(ret):             # <<<<<<<<<<<<<<
 *             self._free_ctx()
 *             raise StreamError(f'Not a valid LZ4 stream: {LZ4F_getErrorName(ret).decode()}')
 */
  __pyx_t_1 = (LZ4F_isError(__pyx_v_ret) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":632
 * 
 *         if LZ4F_isError(ret):
 *             self._free_ctx()             # <<<<<<<<<<<<<<
 *             raise StreamError(f'Not a valid LZ4 stream: {LZ4F_getErrorName(ret).decode()}')
 * 
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_free_ctx(__pyx_v_self);

    /* "fastwarc/stream_io.pyx":633
 *         if LZ4F_isError(ret):
 *             self._free_ctx()
 *             raise StreamError(f'Not a valid LZ4 stream: {LZ4F_getErrorName(ret).decode()}')             # <<<<<<<<<<<<<<
 * 
 *         return out_buf_consumed
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = LZ4F_getErrorName(__pyx_v_ret);
    __pyx_t_4 = __Pyx_decode_c_string(__pyx_t_7, 0, strlen(__pyx_t_7), NULL, NULL, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Not_a_valid_LZ4_stream, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 633, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":631
 *                 break
 * 
 *         if LZ4F_isError(ret):             # <<<<<<<<<<<<<<
 *             self._free_ctx()
 *             raise StreamError(f'Not a valid LZ4 stream: {LZ4F_getErrorName(ret).decode()}')
 */
  }

  /* "fastwarc/stream_io.pyx":635
 *             raise StreamError(f'Not a valid LZ4 stream: {LZ4F_getErrorName(ret).decode()}')
 * 
 *         return out_buf_consumed             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t begin_member(self):
 */
  __pyx_r = __pyx_v_out_buf_consumed;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":596
 *         self.stream_pos = max(0u, self.raw_stream.tell() - self.working_buf_filled)
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.cctx != NULL:
 *             raise StreamError('Compression in progress.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("fastwarc.stream_io.LZ4Stream.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":637
 *         return out_buf_consumed
 * 
 *     cdef size_t begin_member(self):             # <<<<<<<<<<<<<<
 *         if self.frame_started:
 *             return 0
 */

static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_begin_member(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self) {
  size_t __pyx_v_ret;
  size_t __pyx_v_written;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  char const *__pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  size_t __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("begin_member", 0);

  /* "fastwarc/stream_io.pyx":638
 * 
 *     cdef size_t begin_member(self):
 *         if self.frame_started:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_1 = (__pyx_v_self->frame_started != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":639
 *     cdef size_t begin_member(self):
 *         if self.frame_started:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t ret = LZ4F_createCompressionContext(&self.cctx, LZ4F_VERSION)
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":638
 * 
 *     cdef size_t begin_member(self):
 *         if self.frame_started:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":641
 *             return 0
 * 
 *         cdef size_t ret = LZ4F_createCompressionContext(&self.cctx, LZ4F_VERSION)             # <<<<<<<<<<<<<<
 *         if LZ4F_isError(ret):
 *             raise StreamError(f'Failed to create compression context: {LZ4F_getErrorName(ret).decode()}')
 */
  __pyx_v_ret = LZ4F_createCompressionContext((&__pyx_v_self->cctx), LZ4F_VERSION);

  /* "fastwarc/stream_io.pyx":642
 * 
 *         cdef size_t ret = LZ4F_createCompressionContext(&self.cctx, LZ4F_VERSION)
 *         if LZ4F_isError(ret):             # <<<<<<<<<<<<<<
 *             raise StreamError(f'Failed to create compression context: {LZ4F_getErrorName(ret).decode()}')
 * 
 */
  __pyx_t_1 = (LZ4F_isError(__pyx_v_ret) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":643
 *         cdef size_t ret = LZ4F_createCompressionContext(&self.cctx, LZ4F_VERSION)
 *         if LZ4F_isError(ret):
 *             raise StreamError(f'Failed to create compression context: {LZ4F_getErrorName(ret).decode()}')             # <<<<<<<<<<<<<<
 * 
 *         if self.working_buf.size() < LZ4F_HEADER_SIZE_MAX:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 643, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = LZ4F_getErrorName(__pyx_v_ret);
    __pyx_t_5 = __Pyx_decode_c_string(__pyx_t_4, 0, strlen(__pyx_t_4), NULL, NULL, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 643, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Failed_to_create_compression_con, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 643, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 643, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 643, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":642
 * 
 *         cdef size_t ret = LZ4F_createCompressionContext(&self.cctx, LZ4F_VERSION)
 *         if LZ4F_isError(ret):             # <<<<<<<<<<<<<<
 *             raise StreamError(f'Failed to create compression context: {LZ4F_getErrorName(ret).decode()}')
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":645
 *             raise StreamError(f'Failed to create compression context: {LZ4F_getErrorName(ret).decode()}')
 * 
 *         if self.working_buf.size() < LZ4F_HEADER_SIZE_MAX:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(LZ4F_HEADER_SIZE_MAX + 8192u)
 *         cdef size_t written = LZ4F_compressBegin(self.cctx, self.working_buf.data(),
 */
  __pyx_t_1 = ((__pyx_v_self->working_buf.size() < LZ4F_HEADER_SIZE_MAX) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":646
 * 
 *         if self.working_buf.size() < LZ4F_HEADER_SIZE_MAX:
 *             self.working_buf.resize(LZ4F_HEADER_SIZE_MAX + 8192u)             # <<<<<<<<<<<<<<
 *         cdef size_t written = LZ4F_compressBegin(self.cctx, self.working_buf.data(),
 *                                                  self.working_buf.size(), &self.prefs)
 */
    try {
      __pyx_v_self->working_buf.resize((LZ4F_HEADER_SIZE_MAX + 8192U));
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 646, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":645
 *             raise StreamError(f'Failed to create compression context: {LZ4F_getErrorName(ret).decode()}')
 * 
 *         if self.working_buf.size() < LZ4F_HEADER_SIZE_MAX:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(LZ4F_HEADER_SIZE_MAX + 8192u)
 *         cdef size_t written = LZ4F_compressBegin(self.cctx, self.working_buf.data(),
 */
  }

  /* "fastwarc/stream_io.pyx":647
 *         if self.working_buf.size() < LZ4F_HEADER_SIZE_MAX:
 *             self.working_buf.resize(LZ4F_HEADER_SIZE_MAX + 8192u)
 *         cdef size_t written = LZ4F_compressBegin(self.cctx, self.working_buf.data(),             # <<<<<<<<<<<<<<
 *                                                  self.working_buf.size(), &self.prefs)
 *         self.frame_started = True
 */
  __pyx_v_written = LZ4F_compressBegin(__pyx_v_self->cctx, __pyx_v_self->working_buf.data(), __pyx_v_self->working_buf.size(), (&__pyx_v_self->prefs));

  /* "fastwarc/stream_io.pyx":649
 *         cdef size_t written = LZ4F_compressBegin(self.cctx, self.working_buf.data(),
 *                                                  self.working_buf.size(), &self.prefs)
 *         self.frame_started = True             # <<<<<<<<<<<<<<
 * 
 *         return self.raw_stream.write(self.working_buf.data(), written)
 */
  __pyx_v_self->frame_started = 1;

  /* "fastwarc/stream_io.pyx":651
 *         self.frame_started = True
 * 
 *         return self.raw_stream.write(self.working_buf.data(), written)             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t end_member(self):
 */
  __pyx_t_7 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, __pyx_v_self->working_buf.data(), __pyx_v_written); if (unlikely(__pyx_t_7 == ((size_t)-1L))) __PYX_ERR(1, 651, __pyx_L1_error)
  __pyx_r = __pyx_t_7;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":637
 *         return out_buf_consumed
 * 
 *     cdef size_t begin_member(self):             # <<<<<<<<<<<<<<
 *         if self.frame_started:
 *             return 0
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_WriteUnraisable("fastwarc.stream_io.LZ4Stream.begin_member", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":653
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 *     cdef size_t end_member(self):             # <<<<<<<<<<<<<<
 *         if self.cctx == NULL or not self.frame_started:
 *             return 0
 */

static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_end_member(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self) {
  size_t __pyx_v_written;
  size_t __pyx_v_buf_needed;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  size_t __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("end_member", 0);

  /* "fastwarc/stream_io.pyx":654
 * 
 *     cdef size_t end_member(self):
 *         if self.cctx == NULL or not self.frame_started:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_2 = ((__pyx_v_self->cctx == NULL) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = ((!(__pyx_v_self->frame_started != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":655
 *     cdef size_t end_member(self):
 *         if self.cctx == NULL or not self.frame_started:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t written
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":654
 * 
 *     cdef size_t end_member(self):
 *         if self.cctx == NULL or not self.frame_started:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":658
 * 
 *         cdef size_t written
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)             # <<<<<<<<<<<<<<
 *         with nogil:
 *             if self.working_buf.size() < buf_needed:
 */
  __pyx_v_buf_needed = LZ4F_compressBound(0, (&__pyx_v_self->prefs));

  /* "fastwarc/stream_io.pyx":659
 *         cdef size_t written
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             if self.working_buf.size() < buf_needed:
 *                 self.working_buf.resize(buf_needed)
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "fastwarc/stream_io.pyx":660
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)
 *         with nogil:
 *             if self.working_buf.size() < buf_needed:             # <<<<<<<<<<<<<<
 *                 self.working_buf.resize(buf_needed)
 *             written = LZ4F_compressEnd(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)
 */
        __pyx_t_1 = ((__pyx_v_self->working_buf.size() < __pyx_v_buf_needed) != 0);
        if (__pyx_t_1) {

          /* "fastwarc/stream_io.pyx":661
 *         with nogil:
 *             if self.working_buf.size() < buf_needed:
 *                 self.working_buf.resize(buf_needed)             # <<<<<<<<<<<<<<
 *             written = LZ4F_compressEnd(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)
 *             self.frame_started = False
 */
          try {
            __pyx_v_self->working_buf.resize(__pyx_v_buf_needed);
          } catch(...) {
            #ifdef WITH_THREAD
            PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
            #endif
            __Pyx_CppExn2PyErr();
            #ifdef WITH_THREAD
            __Pyx_PyGILState_Release(__pyx_gilstate_save);
            #endif
            __PYX_ERR(1, 661, __pyx_L7_error)
          }

          /* "fastwarc/stream_io.pyx":660
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)
 *         with nogil:
 *             if self.working_buf.size() < buf_needed:             # <<<<<<<<<<<<<<
 *                 self.working_buf.resize(buf_needed)
 *             written = LZ4F_compressEnd(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)
 */
        }

        /* "fastwarc/stream_io.pyx":662
 *             if self.working_buf.size() < buf_needed:
 *                 self.working_buf.resize(buf_needed)
 *             written = LZ4F_compressEnd(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)             # <<<<<<<<<<<<<<
 *             self.frame_started = False
 *         return self.raw_stream.write(self.working_buf.data(), written)
 */
        __pyx_v_written = LZ4F_compressEnd(__pyx_v_self->cctx, __pyx_v_self->working_buf.data(), __pyx_v_self->working_buf.size(), NULL);

        /* "fastwarc/stream_io.pyx":663
 *                 self.working_buf.resize(buf_needed)
 *             written = LZ4F_compressEnd(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)
 *             self.frame_started = False             # <<<<<<<<<<<<<<
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 */
        __pyx_v_self->frame_started = 0;
      }

      /* "fastwarc/stream_io.pyx":659
 *         cdef size_t written
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             if self.working_buf.size() < buf_needed:
 *                 self.working_buf.resize(buf_needed)
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L8;
        }
        __pyx_L7_error: {
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L1_error;
        }
        __pyx_L8:;
      }
  }

  /* "fastwarc/stream_io.pyx":664
 *             written = LZ4F_compressEnd(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)
 *             self.frame_started = False
 *         return self.raw_stream.write(self.working_buf.data(), written)             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, __pyx_v_self->working_buf.data(), __pyx_v_written); if (unlikely(__pyx_t_3 == ((size_t)-1L))) __PYX_ERR(1, 664, __pyx_L1_error)
  __pyx_r = __pyx_t_3;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":653
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 *     cdef size_t end_member(self):             # <<<<<<<<<<<<<<
 *         if self.cctx == NULL or not self.frame_started:
 *             return 0
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("fastwarc.stream_io.LZ4Stream.end_member", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":666
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.dctx != NULL:
 *             raise StreamError('Decompression in progress.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_9LZ4Stream_write(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size) {
  size_t __pyx_v_buf_needed;
  size_t __pyx_v_header_bytes_written;
  size_t __pyx_v_written;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  size_t __pyx_t_5;
  unsigned long __pyx_t_6;
  size_t __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write", 0);

  /* "fastwarc/stream_io.pyx":667
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.dctx != NULL:             # <<<<<<<<<<<<<<
 *             raise StreamError('Decompression in progress.')
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->dctx != NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":668
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.dctx != NULL:
 *             raise StreamError('Decompression in progress.')             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t buf_needed = max(8192u, LZ4F_compressBound(size, &self.prefs))
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 668, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_Decompression_in_progress_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_Decompression_in_progress_2);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 668, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(1, 668, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":667
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.dctx != NULL:             # <<<<<<<<<<<<<<
 *             raise StreamError('Decompression in progress.')
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":670
 *             raise StreamError('Decompression in progress.')
 * 
 *         cdef size_t buf_needed = max(8192u, LZ4F_compressBound(size, &self.prefs))             # <<<<<<<<<<<<<<
 *         if self.working_buf.size() < buf_needed:
 *             self.working_buf.resize(buf_needed)
 */
  __pyx_t_5 = LZ4F_compressBound(__pyx_v_size, (&__pyx_v_self->prefs));
  __pyx_t_6 = 8192U;
  if (((__pyx_t_5 > __pyx_t_6) != 0)) {
    __pyx_t_7 = __pyx_t_5;
  } else {
    __pyx_t_7 = __pyx_t_6;
  }
  __pyx_v_buf_needed = __pyx_t_7;

  /* "fastwarc/stream_io.pyx":671
 * 
 *         cdef size_t buf_needed = max(8192u, LZ4F_compressBound(size, &self.prefs))
 *         if self.working_buf.size() < buf_needed:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(buf_needed)
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->working_buf.size() < __pyx_v_buf_needed) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":672
 *         cdef size_t buf_needed = max(8192u, LZ4F_compressBound(size, &self.prefs))
 *         if self.working_buf.size() < buf_needed:
 *             self.working_buf.resize(buf_needed)             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t header_bytes_written = self.begin_member()
 */
    try {
      __pyx_v_self->working_buf.resize(__pyx_v_buf_needed);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 672, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":671
 * 
 *         cdef size_t buf_needed = max(8192u, LZ4F_compressBound(size, &self.prefs))
 *         if self.working_buf.size() < buf_needed:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(buf_needed)
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":674
 *             self.working_buf.resize(buf_needed)
 * 
 *         cdef size_t header_bytes_written = self.begin_member()             # <<<<<<<<<<<<<<
 *         cdef size_t written = LZ4F_compressUpdate(self.cctx, self.working_buf.data(), self.working_buf.size(),
 *                                                   data, size, NULL)
 */
  __pyx_v_header_bytes_written = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.begin_member(((struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *)__pyx_v_self));

  /* "fastwarc/stream_io.pyx":675
 * 
 *         cdef size_t header_bytes_written = self.begin_member()
 *         cdef size_t written = LZ4F_compressUpdate(self.cctx, self.working_buf.data(), self.working_buf.size(),             # <<<<<<<<<<<<<<
 *                                                   data, size, NULL)
 *         self.stream_pos += written
 */
  __pyx_v_written = LZ4F_compressUpdate(__pyx_v_self->cctx, __pyx_v_self->working_buf.data(), __pyx_v_self->working_buf.size(), __pyx_v_data, __pyx_v_size, NULL);

  /* "fastwarc/stream_io.pyx":677
 *         cdef size_t written = LZ4F_compressUpdate(self.cctx, self.working_buf.data(), self.working_buf.size(),
 *                                                   data, size, NULL)
 *         self.stream_pos += written             # <<<<<<<<<<<<<<
 *         return self.raw_stream.write(self.working_buf.data(), written) + header_bytes_written
 * 
 */
  __pyx_v_self->stream_pos = (__pyx_v_self->stream_pos + __pyx_v_written);

  /* "fastwarc/stream_io.pyx":678
 *                                                   data, size, NULL)
 *         self.stream_pos += written
 *         return self.raw_stream.write(self.working_buf.data(), written) + header_bytes_written             # <<<<<<<<<<<<<<
 * 
 *     cdef void flush(self) except *:
 */
  __pyx_t_7 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, __pyx_v_self->working_buf.data(), __pyx_v_written); if (unlikely(__pyx_t_7 == ((size_t)-1L))) __PYX_ERR(1, 678, __pyx_L1_error)
  __pyx_r = (__pyx_t_7 + __pyx_v_header_bytes_written);
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":666
 *         return self.raw_stream.write(self.working_buf.data(), written)
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.dctx != NULL:
 *             raise StreamError('Decompression in progress.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.LZ4Stream.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":680
 *         return self.raw_stream.write(self.working_buf.data(), written) + header_bytes_written
 * 
 *     cdef void flush(self) except *:             # <<<<<<<<<<<<<<
 *         if self.cctx == NULL:
 *             return
 */

static void __pyx_f_8fastwarc_9stream_io_9LZ4Stream_flush(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self) {
  size_t __pyx_v_buf_needed;
  size_t __pyx_v_written;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  size_t __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("flush", 0);

  /* "fastwarc/stream_io.pyx":681
 * 
 *     cdef void flush(self) except *:
 *         if self.cctx == NULL:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->cctx == NULL) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":682
 *     cdef void flush(self) except *:
 *         if self.cctx == NULL:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)
 */
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":681
 * 
 *     cdef void flush(self) except *:
 *         if self.cctx == NULL:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":684
 *             return
 * 
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)             # <<<<<<<<<<<<<<
 *         if self.working_buf.size() < buf_needed:
 *             self.working_buf.resize(buf_needed)
 */
  __pyx_v_buf_needed = LZ4F_compressBound(0, (&__pyx_v_self->prefs));

  /* "fastwarc/stream_io.pyx":685
 * 
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)
 *         if self.working_buf.size() < buf_needed:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(buf_needed)
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->working_buf.size() < __pyx_v_buf_needed) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":686
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)
 *         if self.working_buf.size() < buf_needed:
 *             self.working_buf.resize(buf_needed)             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t written = LZ4F_flush(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)
 */
    try {
      __pyx_v_self->working_buf.resize(__pyx_v_buf_needed);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 686, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":685
 * 
 *         cdef size_t buf_needed = LZ4F_compressBound(0, &self.prefs)
 *         if self.working_buf.size() < buf_needed:             # <<<<<<<<<<<<<<
 *             self.working_buf.resize(buf_needed)
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":688
 *             self.working_buf.resize(buf_needed)
 * 
 *         cdef size_t written = LZ4F_flush(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)             # <<<<<<<<<<<<<<
 *         self.raw_stream.write(self.working_buf.data(), written)
 *         self.stream_pos += written
 */
  __pyx_v_written = LZ4F_flush(__pyx_v_self->cctx, __pyx_v_self->working_buf.data(), __pyx_v_self->working_buf.size(), NULL);

  /* "fastwarc/stream_io.pyx":689
 * 
 *         cdef size_t written = LZ4F_flush(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)
 *         self.raw_stream.write(self.working_buf.data(), written)             # <<<<<<<<<<<<<<
 *         self.stream_pos += written
 *         self.raw_stream.flush()
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, __pyx_v_self->working_buf.data(), __pyx_v_written); if (unlikely(__pyx_t_2 == ((size_t)-1L))) __PYX_ERR(1, 689, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":690
 *         cdef size_t written = LZ4F_flush(self.cctx, self.working_buf.data(), self.working_buf.size(), NULL)
 *         self.raw_stream.write(self.working_buf.data(), written)
 *         self.stream_pos += written             # <<<<<<<<<<<<<<
 *         self.raw_stream.flush()
 * 
 */
  __pyx_v_self->stream_pos = (__pyx_v_self->stream_pos + __pyx_v_written);

  /* "fastwarc/stream_io.pyx":691
 *         self.raw_stream.write(self.working_buf.data(), written)
 *         self.stream_pos += written
 *         self.raw_stream.flush()             # <<<<<<<<<<<<<<
 * 
 *     cdef void close(self) except *:
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->flush(__pyx_v_self->raw_stream); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 691, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":680
 *         return self.raw_stream.write(self.working_buf.data(), written) + header_bytes_written
 * 
 *     cdef void flush(self) except *:             # <<<<<<<<<<<<<<
 *         if self.cctx == NULL:
 *             return
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.LZ4Stream.flush", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":693
 *         self.raw_stream.flush()
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         if self.cctx != NULL:
 *             self.end_member()
 */

static void __pyx_f_8fastwarc_9stream_io_9LZ4Stream_close(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("close", 0);

  /* "fastwarc/stream_io.pyx":694
 * 
 *     cdef void close(self) except *:
 *         if self.cctx != NULL:             # <<<<<<<<<<<<<<
 *             self.end_member()
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->cctx != NULL) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":695
 *     cdef void close(self) except *:
 *         if self.cctx != NULL:
 *             self.end_member()             # <<<<<<<<<<<<<<
 * 
 *         self._free_ctx()
 */
    (void)(((struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.end_member(((struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *)__pyx_v_self)));

    /* "fastwarc/stream_io.pyx":694
 * 
 *     cdef void close(self) except *:
 *         if self.cctx != NULL:             # <<<<<<<<<<<<<<
 *             self.end_member()
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":697
 *             self.end_member()
 * 
 *         self._free_ctx()             # <<<<<<<<<<<<<<
 * 
 *     cdef void _free_ctx(self) nogil:
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_vtab)->_free_ctx(__pyx_v_self);

  /* "fastwarc/stream_io.pyx":693
 *         self.raw_stream.flush()
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         if self.cctx != NULL:
 *             self.end_member()
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":699
 *         self._free_ctx()
 * 
 *     cdef void _free_ctx(self) nogil:             # <<<<<<<<<<<<<<
 *         if self.cctx != NULL:
 *             LZ4F_freeCompressionContext(self.cctx)
 */

static void __pyx_f_8fastwarc_9stream_io_9LZ4Stream__free_ctx(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *__pyx_v_self) {
  int __pyx_t_1;

  /* "fastwarc/stream_io.pyx":700
 * 
 *     cdef void _free_ctx(self) nogil:
 *         if self.cctx != NULL:             # <<<<<<<<<<<<<<
 *             LZ4F_freeCompressionContext(self.cctx)
 *             self.cctx = NULL
 */
  __pyx_t_1 = ((__pyx_v_self->cctx != NULL) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":701
 *     cdef void _free_ctx(self) nogil:
 *         if self.cctx != NULL:
 *             LZ4F_freeCompressionContext(self.cctx)             # <<<<<<<<<<<<<<
 *             self.cctx = NULL
 * 
 */
    (void)(LZ4F_freeCompressionContext(__pyx_v_self->cctx));

    /* "fastwarc/stream_io.pyx":702
 *         if self.cctx != NULL:
 *             LZ4F_freeCompressionContext(self.cctx)
 *             self.cctx = NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.dctx != NULL:
 */
    __pyx_v_self->cctx = NULL;

    /* "fastwarc/stream_io.pyx":700
 * 
 *     cdef void _free_ctx(self) nogil:
 *         if self.cctx != NULL:             # <<<<<<<<<<<<<<
 *             LZ4F_freeCompressionContext(self.cctx)
 *             self.cctx = NULL
 */
  }

  /* "fastwarc/stream_io.pyx":704
 *             self.cctx = NULL
 * 
 *         if self.dctx != NULL:             # <<<<<<<<<<<<<<
 *             LZ4F_freeDecompressionContext(self.dctx)
 *             self.dctx = NULL
 */
  __pyx_t_1 = ((__pyx_v_self->dctx != NULL) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":705
 * 
 *         if self.dctx != NULL:
 *             LZ4F_freeDecompressionContext(self.dctx)             # <<<<<<<<<<<<<<
 *             self.dctx = NULL
 * 
 */
    (void)(LZ4F_freeDecompressionContext(__pyx_v_self->dctx));

    /* "fastwarc/stream_io.pyx":706
 *         if self.dctx != NULL:
 *             LZ4F_freeDecompressionContext(self.dctx)
 *             self.dctx = NULL             # <<<<<<<<<<<<<<
 * 
 *         if not self.working_buf.empty():
 */
    __pyx_v_self->dctx = NULL;

    /* "fastwarc/stream_io.pyx":704
 *             self.cctx = NULL
 * 
 *         if self.dctx != NULL:             # <<<<<<<<<<<<<<
 *             LZ4F_freeDecompressionContext(self.dctx)
 *             self.dctx = NULL
 */
  }

  /* "fastwarc/stream_io.pyx":708
 *             self.dctx = NULL
 * 
 *         if not self.working_buf.empty():             # <<<<<<<<<<<<<<
 *             self.working_buf.clear()
 *         self.working_buf_filled = 0u
 */
  __pyx_t_1 = ((!(__pyx_v_self->working_buf.empty() != 0)) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":709
 * 
 *         if not self.working_buf.empty():
 *             self.working_buf.clear()             # <<<<<<<<<<<<<<
 *         self.working_buf_filled = 0u
 * 
 */
    __pyx_v_self->working_buf.clear();

    /* "fastwarc/stream_io.pyx":708
 *             self.dctx = NULL
 * 
 *         if not self.working_buf.empty():             # <<<<<<<<<<<<<<
 *             self.working_buf.clear()
 *         self.working_buf_filled = 0u
 */
  }

  /* "fastwarc/stream_io.pyx":710
 *         if not self.working_buf.empty():
 *             self.working_buf.clear()
 *         self.working_buf_filled = 0u             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_self->working_buf_filled = 0U;

  /* "fastwarc/stream_io.pyx":699
 *         self._free_ctx()
 * 
 *     cdef void _free_ctx(self) nogil:             # <<<<<<<<<<<<<<
 *         if self.cctx != NULL:
 *             LZ4F_freeCompressionContext(self.cctx)
 */

  /* function exit code */
}

/* "fastwarc/stream_io.pyx":734
 *     :type lgblock: int
 *     """
 *     def __init__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_12BrotliStream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_12BrotliStream_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_12BrotliStream___init__(((struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_12BrotliStream___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":737
 *         pass
 * 
 *     def __cinit__(self, raw_stream, size_t quality=11, size_t lgwin=22, size_t lgblock=0):             # <<<<<<<<<<<<<<
 *         self.raw_stream = raw_stream
 *         self.quality = quality
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_12BrotliStream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_12BrotliStream_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_raw_stream = 0;
  size_t __pyx_v_quality;
  size_t __pyx_v_lgwin;
  size_t __pyx_v_lgblock;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_raw_stream,&__pyx_n_s_quality,&__pyx_n_s_lgwin,&__pyx_n_s_lgblock,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_raw_stream)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quality);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_lgwin);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_lgblock);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 737, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_raw_stream = values[0];
    if (values[1]) {
      __pyx_v_quality = __Pyx_PyInt_As_size_t(values[1]); if (unlikely((__pyx_v_quality == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 737, __pyx_L3_error)
    } else {
      __pyx_v_quality = ((size_t)11);
    }
    if (values[2]) {
      __pyx_v_lgwin = __Pyx_PyInt_As_size_t(values[2]); if (unlikely((__pyx_v_lgwin == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 737, __pyx_L3_error)
    } else {
      __pyx_v_lgwin = ((size_t)22);
    }
    if (values[3]) {
      __pyx_v_lgblock = __Pyx_PyInt_As_size_t(values[3]); if (unlikely((__pyx_v_lgblock == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 737, __pyx_L3_error)
    } else {
      __pyx_v_lgblock = ((size_t)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 737, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_12BrotliStream_2__cinit__(((struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *)__pyx_v_self), __pyx_v_raw_stream, __pyx_v_quality, __pyx_v_lgwin, __pyx_v_lgblock);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_12BrotliStream_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, PyObject *__pyx_v_raw_stream, size_t __pyx_v_quality, size_t __pyx_v_lgwin, size_t __pyx_v_lgblock) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "fastwarc/stream_io.pyx":738
 * 
 *     def __cinit__(self, raw_stream, size_t quality=11, size_t lgwin=22, size_t lgblock=0):
 *         self.raw_stream = raw_stream             # <<<<<<<<<<<<<<
 *         self.quality = quality
 *         self.lgwin = lgwin
 */
  if (!(likely(((__pyx_v_raw_stream) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_raw_stream, __pyx_ptype_8fastwarc_9stream_io_IOStream))))) __PYX_ERR(1, 738, __pyx_L1_error)
  __pyx_t_1 = __pyx_v_raw_stream;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->raw_stream);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->raw_stream));
  __pyx_v_self->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":739
 *     def __cinit__(self, raw_stream, size_t quality=11, size_t lgwin=22, size_t lgblock=0):
 *         self.raw_stream = raw_stream
 *         self.quality = quality             # <<<<<<<<<<<<<<
 *         self.lgwin = lgwin
 *         self.lgblock = lgblock
 */
  __pyx_v_self->quality = __pyx_v_quality;

  /* "fastwarc/stream_io.pyx":740
 *         self.raw_stream = raw_stream
 *         self.quality = quality
 *         self.lgwin = lgwin             # <<<<<<<<<<<<<<
 *         self.lgblock = lgblock
 *         self.stream_state = CompressingStreamState.UNINIT
 */
  __pyx_v_self->lgwin = __pyx_v_lgwin;

  /* "fastwarc/stream_io.pyx":741
 *         self.quality = quality
 *         self.lgwin = lgwin
 *         self.lgblock = lgblock             # <<<<<<<<<<<<<<
 *         self.stream_state = CompressingStreamState.UNINIT
 *         self.compressor = None
 */
  __pyx_v_self->lgblock = __pyx_v_lgblock;

  /* "fastwarc/stream_io.pyx":742
 *         self.lgwin = lgwin
 *         self.lgblock = lgblock
 *         self.stream_state = CompressingStreamState.UNINIT             # <<<<<<<<<<<<<<
 *         self.compressor = None
 * 
 */
  __pyx_v_self->stream_state = UNINIT;

  /* "fastwarc/stream_io.pyx":743
 *         self.lgblock = lgblock
 *         self.stream_state = CompressingStreamState.UNINIT
 *         self.compressor = None             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t begin_member(self):
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->compressor);
  __Pyx_DECREF(__pyx_v_self->compressor);
  __pyx_v_self->compressor = Py_None;

  /* "fastwarc/stream_io.pyx":737
 *         pass
 * 
 *     def __cinit__(self, raw_stream, size_t quality=11, size_t lgwin=22, size_t lgblock=0):             # <<<<<<<<<<<<<<
 *         self.raw_stream = raw_stream
 *         self.quality = quality
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":745
 *         self.compressor = None
 * 
 *     cdef size_t begin_member(self):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_begin_member(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("begin_member", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":748
 *         pass
 * 
 *     cdef size_t end_member(self):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_end_member(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("end_member", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":751
 *         pass
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             raise StreamError('Compression in progress.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_read(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size) {
  std::string __pyx_v_tmp_buffer;
  size_t __pyx_v_bytes_read;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  size_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  std::string __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  size_t __pyx_t_13;
  size_t __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("read", 0);

  /* "fastwarc/stream_io.pyx":752
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             raise StreamError('Compression in progress.')
 *         elif self.stream_state == 0:
 */
  switch (__pyx_v_self->stream_state) {
    case COMPRESSING:

    /* "fastwarc/stream_io.pyx":753
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             raise StreamError('Compression in progress.')             # <<<<<<<<<<<<<<
 *         elif self.stream_state == 0:
 *             self.compressor = brotli.Decompressor()
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 753, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_kp_u_Compression_in_progress) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_Compression_in_progress);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 753, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(1, 753, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":752
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             raise StreamError('Compression in progress.')
 *         elif self.stream_state == 0:
 */
    break;
    case 0:

    /* "fastwarc/stream_io.pyx":755
 *             raise StreamError('Compression in progress.')
 *         elif self.stream_state == 0:
 *             self.compressor = brotli.Decompressor()             # <<<<<<<<<<<<<<
 *             self.stream_state = CompressingStreamState.DECOMPRESSING
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_brotli); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Decompressor); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_GOTREF(__pyx_v_self->compressor);
    __Pyx_DECREF(__pyx_v_self->compressor);
    __pyx_v_self->compressor = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "fastwarc/stream_io.pyx":756
 *         elif self.stream_state == 0:
 *             self.compressor = brotli.Decompressor()
 *             self.stream_state = CompressingStreamState.DECOMPRESSING             # <<<<<<<<<<<<<<
 * 
 *         cdef string tmp_buffer
 */
    __pyx_v_self->stream_state = DECOMPRESSING;

    /* "fastwarc/stream_io.pyx":754
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             raise StreamError('Compression in progress.')
 *         elif self.stream_state == 0:             # <<<<<<<<<<<<<<
 *             self.compressor = brotli.Decompressor()
 *             self.stream_state = CompressingStreamState.DECOMPRESSING
 */
    break;
    default: break;
  }

  /* "fastwarc/stream_io.pyx":759
 * 
 *         cdef string tmp_buffer
 *         tmp_buffer.resize(size)             # <<<<<<<<<<<<<<
 *         cdef size_t bytes_read = self.raw_stream.read(tmp_buffer.data(), size)
 *         tmp_buffer.resize(bytes_read)
 */
  try {
    __pyx_v_tmp_buffer.resize(__pyx_v_size);
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 759, __pyx_L1_error)
  }

  /* "fastwarc/stream_io.pyx":760
 *         cdef string tmp_buffer
 *         tmp_buffer.resize(size)
 *         cdef size_t bytes_read = self.raw_stream.read(tmp_buffer.data(), size)             # <<<<<<<<<<<<<<
 *         tmp_buffer.resize(bytes_read)
 * 
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->read(__pyx_v_self->raw_stream, __pyx_v_tmp_buffer.data(), __pyx_v_size); if (unlikely(__pyx_t_4 == ((size_t)-1L))) __PYX_ERR(1, 760, __pyx_L1_error)
  __pyx_v_bytes_read = __pyx_t_4;

  /* "fastwarc/stream_io.pyx":761
 *         tmp_buffer.resize(size)
 *         cdef size_t bytes_read = self.raw_stream.read(tmp_buffer.data(), size)
 *         tmp_buffer.resize(bytes_read)             # <<<<<<<<<<<<<<
 * 
 *         try:
 */
  try {
    __pyx_v_tmp_buffer.resize(__pyx_v_bytes_read);
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 761, __pyx_L1_error)
  }

  /* "fastwarc/stream_io.pyx":763
 *         tmp_buffer.resize(bytes_read)
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             self.working_buf.append(<string>self.compressor.process(tmp_buffer))
 *         except brotli.error:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
    __Pyx_XGOTREF(__pyx_t_5);
    __Pyx_XGOTREF(__pyx_t_6);
    __Pyx_XGOTREF(__pyx_t_7);
    /*try:*/ {

      /* "fastwarc/stream_io.pyx":764
 * 
 *         try:
 *             self.working_buf.append(<string>self.compressor.process(tmp_buffer))             # <<<<<<<<<<<<<<
 *         except brotli.error:
 *             raise StreamError(f'Not a valid Brotli stream')
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->compressor, __pyx_n_s_process); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 764, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __pyx_convert_PyBytes_string_to_py_std__in_string(__pyx_v_tmp_buffer); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 764, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_8, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 764, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_9 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 764, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      try {
        __pyx_v_self->working_buf.append(((std::string)__pyx_t_9));
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(1, 764, __pyx_L3_error)
      }

      /* "fastwarc/stream_io.pyx":763
 *         tmp_buffer.resize(bytes_read)
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             self.working_buf.append(<string>self.compressor.process(tmp_buffer))
 *         except brotli.error:
 */
    }
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "fastwarc/stream_io.pyx":765
 *         try:
 *             self.working_buf.append(<string>self.compressor.process(tmp_buffer))
 *         except brotli.error:             # <<<<<<<<<<<<<<
 *             raise StreamError(f'Not a valid Brotli stream')
 * 
 */
    __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_3, &__pyx_t_2);
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_brotli); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 765, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_error); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 765, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_11 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_10);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_ErrRestore(__pyx_t_1, __pyx_t_3, __pyx_t_2);
    __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_2 = 0;
    if (__pyx_t_11) {
      __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_1) < 0) __PYX_ERR(1, 765, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GOTREF(__pyx_t_1);

      /* "fastwarc/stream_io.pyx":766
 *             self.working_buf.append(<string>self.compressor.process(tmp_buffer))
 *         except brotli.error:
 *             raise StreamError(f'Not a valid Brotli stream')             # <<<<<<<<<<<<<<
 * 
 *         bytes_read = min(self.working_buf.size(), size)
 */
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 766, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_12 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_12, __pyx_kp_u_Not_a_valid_Brotli_stream) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_u_Not_a_valid_Brotli_stream);
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 766, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_Raise(__pyx_t_10, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __PYX_ERR(1, 766, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "fastwarc/stream_io.pyx":763
 *         tmp_buffer.resize(bytes_read)
 * 
 *         try:             # <<<<<<<<<<<<<<
 *             self.working_buf.append(<string>self.compressor.process(tmp_buffer))
 *         except brotli.error:
 */
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_XGIVEREF(__pyx_t_6);
    __Pyx_XGIVEREF(__pyx_t_7);
    __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "fastwarc/stream_io.pyx":768
 *             raise StreamError(f'Not a valid Brotli stream')
 * 
 *         bytes_read = min(self.working_buf.size(), size)             # <<<<<<<<<<<<<<
 *         memcpy(out, self.working_buf.data(), bytes_read)
 *         self.working_buf = self.working_buf.substr(bytes_read)
 */
  __pyx_t_4 = __pyx_v_size;
  __pyx_t_13 = __pyx_v_self->working_buf.size();
  if (((__pyx_t_4 < __pyx_t_13) != 0)) {
    __pyx_t_14 = __pyx_t_4;
  } else {
    __pyx_t_14 = __pyx_t_13;
  }
  __pyx_v_bytes_read = __pyx_t_14;

  /* "fastwarc/stream_io.pyx":769
 * 
 *         bytes_read = min(self.working_buf.size(), size)
 *         memcpy(out, self.working_buf.data(), bytes_read)             # <<<<<<<<<<<<<<
 *         self.working_buf = self.working_buf.substr(bytes_read)
 *         return bytes_read
 */
  (void)(memcpy(__pyx_v_out, __pyx_v_self->working_buf.data(), __pyx_v_bytes_read));

  /* "fastwarc/stream_io.pyx":770
 *         bytes_read = min(self.working_buf.size(), size)
 *         memcpy(out, self.working_buf.data(), bytes_read)
 *         self.working_buf = self.working_buf.substr(bytes_read)             # <<<<<<<<<<<<<<
 *         return bytes_read
 * 
 */
  try {
    __pyx_t_9 = __pyx_v_self->working_buf.substr(__pyx_v_bytes_read);
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 770, __pyx_L1_error)
  }
  __pyx_v_self->working_buf = __pyx_t_9;

  /* "fastwarc/stream_io.pyx":771
 *         memcpy(out, self.working_buf.data(), bytes_read)
 *         self.working_buf = self.working_buf.substr(bytes_read)
 *         return bytes_read             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_bytes_read;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":751
 *         pass
 * 
 *     cdef size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             raise StreamError('Compression in progress.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":774
 * 
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             raise StreamError('Decompression in progress.')
 */

static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_write(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size) {
  PyObject *__pyx_v_compressed = 0;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  Py_ssize_t __pyx_t_6;
  size_t __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write", 0);

  /* "fastwarc/stream_io.pyx":775
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:             # <<<<<<<<<<<<<<
 *             raise StreamError('Decompression in progress.')
 *         elif self.stream_state == 0:
 */
  switch (__pyx_v_self->stream_state) {
    case DECOMPRESSING:

    /* "fastwarc/stream_io.pyx":776
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             raise StreamError('Decompression in progress.')             # <<<<<<<<<<<<<<
 *         elif self.stream_state == 0:
 *             self.compressor = brotli.Compressor()
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 776, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_kp_u_Decompression_in_progress_2) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_Decompression_in_progress_2);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 776, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(1, 776, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":775
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:             # <<<<<<<<<<<<<<
 *             raise StreamError('Decompression in progress.')
 *         elif self.stream_state == 0:
 */
    break;
    case 0:

    /* "fastwarc/stream_io.pyx":778
 *             raise StreamError('Decompression in progress.')
 *         elif self.stream_state == 0:
 *             self.compressor = brotli.Compressor()             # <<<<<<<<<<<<<<
 *             self.stream_state = CompressingStreamState.COMPRESSING
 *         cdef bytes compressed = self.compressor.process(<bytes>data[:size])
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_brotli); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Compressor); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_GOTREF(__pyx_v_self->compressor);
    __Pyx_DECREF(__pyx_v_self->compressor);
    __pyx_v_self->compressor = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "fastwarc/stream_io.pyx":779
 *         elif self.stream_state == 0:
 *             self.compressor = brotli.Compressor()
 *             self.stream_state = CompressingStreamState.COMPRESSING             # <<<<<<<<<<<<<<
 *         cdef bytes compressed = self.compressor.process(<bytes>data[:size])
 *         return self.raw_stream.write(<char*>compressed, len(compressed))
 */
    __pyx_v_self->stream_state = COMPRESSING;

    /* "fastwarc/stream_io.pyx":777
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             raise StreamError('Decompression in progress.')
 *         elif self.stream_state == 0:             # <<<<<<<<<<<<<<
 *             self.compressor = brotli.Compressor()
 *             self.stream_state = CompressingStreamState.COMPRESSING
 */
    break;
    default: break;
  }

  /* "fastwarc/stream_io.pyx":780
 *             self.compressor = brotli.Compressor()
 *             self.stream_state = CompressingStreamState.COMPRESSING
 *         cdef bytes compressed = self.compressor.process(<bytes>data[:size])             # <<<<<<<<<<<<<<
 *         return self.raw_stream.write(<char*>compressed, len(compressed))
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->compressor, __pyx_n_s_process); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_data + 0, __pyx_v_size - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 780, __pyx_L1_error)
  __pyx_v_compressed = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":781
 *             self.stream_state = CompressingStreamState.COMPRESSING
 *         cdef bytes compressed = self.compressor.process(<bytes>data[:size])
 *         return self.raw_stream.write(<char*>compressed, len(compressed))             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t tell(self) except -1:
 */
  if (unlikely(__pyx_v_compressed == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
    __PYX_ERR(1, 781, __pyx_L1_error)
  }
  __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_v_compressed); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(1, 781, __pyx_L1_error)
  if (unlikely(__pyx_v_compressed == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(1, 781, __pyx_L1_error)
  }
  __pyx_t_6 = PyBytes_GET_SIZE(__pyx_v_compressed); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(1, 781, __pyx_L1_error)
  __pyx_t_7 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, ((char *)__pyx_t_5), __pyx_t_6); if (unlikely(__pyx_t_7 == ((size_t)-1L))) __PYX_ERR(1, 781, __pyx_L1_error)
  __pyx_r = __pyx_t_7;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":774
 * 
 * 
 *     cdef size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.DECOMPRESSING:
 *             raise StreamError('Decompression in progress.')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_compressed);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":783
 *         return self.raw_stream.write(<char*>compressed, len(compressed))
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         return self.raw_stream.tell()
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_12BrotliStream_tell(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  size_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("tell", 0);

  /* "fastwarc/stream_io.pyx":784
 * 
 *     cdef size_t tell(self) except -1:
 *         return self.raw_stream.tell()             # <<<<<<<<<<<<<<
 * 
 *     cdef void seek(self, size_t offset) except *:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->tell(__pyx_v_self->raw_stream); if (unlikely(__pyx_t_1 == ((size_t)-1L))) __PYX_ERR(1, 784, __pyx_L1_error)
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":783
 *         return self.raw_stream.write(<char*>compressed, len(compressed))
 * 
 *     cdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         return self.raw_stream.tell()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":786
 *         return self.raw_stream.tell()
 * 
 *     cdef void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         self.raw_stream.seek(offset)
 * 
 */

static void __pyx_f_8fastwarc_9stream_io_12BrotliStream_seek(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self, size_t __pyx_v_offset) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("seek", 0);

  /* "fastwarc/stream_io.pyx":787
 * 
 *     cdef void seek(self, size_t offset) except *:
 *         self.raw_stream.seek(offset)             # <<<<<<<<<<<<<<
 * 
 *     cdef void flush(self)  except *:
 */
  ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->seek(__pyx_v_self->raw_stream, __pyx_v_offset); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 787, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":786
 *         return self.raw_stream.tell()
 * 
 *     cdef void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         self.raw_stream.seek(offset)
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":789
 *         self.raw_stream.seek(offset)
 * 
 *     cdef void flush(self)  except *:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             compressed = self.compressor.flush()
 */

static void __pyx_f_8fastwarc_9stream_io_12BrotliStream_flush(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self) {
  PyObject *__pyx_v_compressed = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  Py_ssize_t __pyx_t_6;
  size_t __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("flush", 0);

  /* "fastwarc/stream_io.pyx":790
 * 
 *     cdef void flush(self)  except *:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             compressed = self.compressor.flush()
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 */
  __pyx_t_1 = ((__pyx_v_self->stream_state == COMPRESSING) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":791
 *     cdef void flush(self)  except *:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             compressed = self.compressor.flush()             # <<<<<<<<<<<<<<
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 *             self.raw_stream.flush()
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->compressor, __pyx_n_s_flush); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 791, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 791, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_compressed = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "fastwarc/stream_io.pyx":792
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             compressed = self.compressor.flush()
 *             self.raw_stream.write(<char*>compressed, len(compressed))             # <<<<<<<<<<<<<<
 *             self.raw_stream.flush()
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_compressed); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(1, 792, __pyx_L1_error)
    __pyx_t_6 = PyObject_Length(__pyx_v_compressed); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(1, 792, __pyx_L1_error)
    __pyx_t_7 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, ((char *)__pyx_t_5), __pyx_t_6); if (unlikely(__pyx_t_7 == ((size_t)-1L))) __PYX_ERR(1, 792, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":793
 *             compressed = self.compressor.flush()
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 *             self.raw_stream.flush()             # <<<<<<<<<<<<<<
 * 
 *     cdef void close(self) except *:
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->flush(__pyx_v_self->raw_stream); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 793, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":790
 * 
 *     cdef void flush(self)  except *:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             compressed = self.compressor.flush()
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 */
  }

  /* "fastwarc/stream_io.pyx":789
 *         self.raw_stream.seek(offset)
 * 
 *     cdef void flush(self)  except *:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             compressed = self.compressor.flush()
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.flush", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_compressed);
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":795
 *             self.raw_stream.flush()
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             compressed = self.compressor.finish()
 */

static void __pyx_f_8fastwarc_9stream_io_12BrotliStream_close(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *__pyx_v_self) {
  PyObject *__pyx_v_compressed = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  Py_ssize_t __pyx_t_6;
  size_t __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("close", 0);

  /* "fastwarc/stream_io.pyx":796
 * 
 *     cdef void close(self) except *:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             compressed = self.compressor.finish()
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 */
  __pyx_t_1 = ((__pyx_v_self->stream_state == COMPRESSING) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":797
 *     cdef void close(self) except *:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             compressed = self.compressor.finish()             # <<<<<<<<<<<<<<
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 *         self.compressor = None
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->compressor, __pyx_n_s_finish); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 797, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 797, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_compressed = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "fastwarc/stream_io.pyx":798
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             compressed = self.compressor.finish()
 *             self.raw_stream.write(<char*>compressed, len(compressed))             # <<<<<<<<<<<<<<
 *         self.compressor = None
 *         self.stream_state = CompressingStreamState.UNINIT
 */
    __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_compressed); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(1, 798, __pyx_L1_error)
    __pyx_t_6 = PyObject_Length(__pyx_v_compressed); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(1, 798, __pyx_L1_error)
    __pyx_t_7 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->raw_stream->__pyx_vtab)->write(__pyx_v_self->raw_stream, ((char *)__pyx_t_5), __pyx_t_6); if (unlikely(__pyx_t_7 == ((size_t)-1L))) __PYX_ERR(1, 798, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":796
 * 
 *     cdef void close(self) except *:
 *         if self.stream_state == CompressingStreamState.COMPRESSING:             # <<<<<<<<<<<<<<
 *             compressed = self.compressor.finish()
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 */
  }

  /* "fastwarc/stream_io.pyx":799
 *             compressed = self.compressor.finish()
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 *         self.compressor = None             # <<<<<<<<<<<<<<
 *         self.stream_state = CompressingStreamState.UNINIT
 *         self.working_buf.clear()
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->compressor);
  __Pyx_DECREF(__pyx_v_self->compressor);
  __pyx_v_self->compressor = Py_None;

  /* "fastwarc/stream_io.pyx":800
 *             self.raw_stream.write(<char*>compressed, len(compressed))
 *         self.compressor = None
 *         self.stream_state = CompressingStreamState.UNINIT             # <<<<<<<<<<<<<<
 *         self.working_buf.clear()
 * 
 */
  __pyx_v_self->stream_state = UNINIT;

  /* "fastwarc/stream_io.pyx":801
 *         self.compressor = None
 *         self.stream_state = CompressingStreamState.UNINIT
 *         self.working_buf.clear()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_self->working_buf.clear();

  /* "fastwarc/stream_io.pyx":795
 *             self.raw_stream.flush()
 * 
 *     cdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         if self.stream_state == CompressingStreamState.COMPRESSING:
 *             compressed = self.compressor.finish()
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.BrotliStream.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_compressed);
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pyx":820
 *     """
 * 
 *     def __init__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_14BufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_14BufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_14BufferedReader___init__(((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_14BufferedReader___init__(CYTHON_UNUSED struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":823
 *         pass
 * 
 *     def __cinit__(self, IOStream stream, size_t buf_size=65536, bint negotiate_stream=True):             # <<<<<<<<<<<<<<
 *         self.stream = stream
 *         self.buf = string()
 */

/* Python wrapper */
static int __pyx_pw_8fastwarc_9stream_io_14BufferedReader_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8fastwarc_9stream_io_14BufferedReader_3__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream = 0;
  size_t __pyx_v_buf_size;
  int __pyx_v_negotiate_stream;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stream,&__pyx_n_s_buf_size,&__pyx_n_s_negotiate_stream,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stream)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_buf_size);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_negotiate_stream);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 823, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)values[0]);
    if (values[1]) {
      __pyx_v_buf_size = __Pyx_PyInt_As_size_t(values[1]); if (unlikely((__pyx_v_buf_size == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 823, __pyx_L3_error)
    } else {
      __pyx_v_buf_size = ((size_t)0x10000);
    }
    if (values[2]) {
      __pyx_v_negotiate_stream = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_negotiate_stream == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 823, __pyx_L3_error)
    } else {
      __pyx_v_negotiate_stream = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 823, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_stream), __pyx_ptype_8fastwarc_9stream_io_IOStream, 1, "stream", 0))) __PYX_ERR(1, 823, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_14BufferedReader_2__cinit__(((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self), __pyx_v_stream, __pyx_v_buf_size, __pyx_v_negotiate_stream);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_8fastwarc_9stream_io_14BufferedReader_2__cinit__(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, struct __pyx_obj_8fastwarc_9stream_io_IOStream *__pyx_v_stream, size_t __pyx_v_buf_size, int __pyx_v_negotiate_stream) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  std::string __pyx_t_1;
  size_t __pyx_t_2;
  unsigned long __pyx_t_3;
  size_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);

  /* "fastwarc/stream_io.pyx":824
 * 
 *     def __cinit__(self, IOStream stream, size_t buf_size=65536, bint negotiate_stream=True):
 *         self.stream = stream             # <<<<<<<<<<<<<<
 *         self.buf = string()
 *         self.buf.resize(max(4096u, buf_size))
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_stream));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_stream));
  __Pyx_GOTREF(__pyx_v_self->stream);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->stream));
  __pyx_v_self->stream = __pyx_v_stream;

  /* "fastwarc/stream_io.pyx":825
 *     def __cinit__(self, IOStream stream, size_t buf_size=65536, bint negotiate_stream=True):
 *         self.stream = stream
 *         self.buf = string()             # <<<<<<<<<<<<<<
 *         self.buf.resize(max(4096u, buf_size))
 *         self.buf_view = string_view()
 */
  try {
    __pyx_t_1 = std::string();
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 825, __pyx_L1_error)
  }
  __pyx_v_self->buf = __pyx_t_1;

  /* "fastwarc/stream_io.pyx":826
 *         self.stream = stream
 *         self.buf = string()
 *         self.buf.resize(max(4096u, buf_size))             # <<<<<<<<<<<<<<
 *         self.buf_view = string_view()
 *         self.limited_buf_view = string_view()
 */
  __pyx_t_2 = __pyx_v_buf_size;
  __pyx_t_3 = 4096U;
  if (((__pyx_t_2 > __pyx_t_3) != 0)) {
    __pyx_t_4 = __pyx_t_2;
  } else {
    __pyx_t_4 = __pyx_t_3;
  }
  try {
    __pyx_v_self->buf.resize(__pyx_t_4);
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 826, __pyx_L1_error)
  }

  /* "fastwarc/stream_io.pyx":827
 *         self.buf = string()
 *         self.buf.resize(max(4096u, buf_size))
 *         self.buf_view = string_view()             # <<<<<<<<<<<<<<
 *         self.limited_buf_view = string_view()
 *         self.limit = strnpos
 */
  __pyx_v_self->buf_view = std::string_view();

  /* "fastwarc/stream_io.pyx":828
 *         self.buf.resize(max(4096u, buf_size))
 *         self.buf_view = string_view()
 *         self.limited_buf_view = string_view()             # <<<<<<<<<<<<<<
 *         self.limit = strnpos
 *         self.limit_consumed = 0
 */
  __pyx_v_self->limited_buf_view = std::string_view();

  /* "fastwarc/stream_io.pyx":829
 *         self.buf_view = string_view()
 *         self.limited_buf_view = string_view()
 *         self.limit = strnpos             # <<<<<<<<<<<<<<
 *         self.limit_consumed = 0
 *         self.stream_is_compressed = isinstance(stream, CompressingStream)
 */
  __pyx_v_self->limit = std::string::npos;

  /* "fastwarc/stream_io.pyx":830
 *         self.limited_buf_view = string_view()
 *         self.limit = strnpos
 *         self.limit_consumed = 0             # <<<<<<<<<<<<<<
 *         self.stream_is_compressed = isinstance(stream, CompressingStream)
 *         self.stream_started = False
 */
  __pyx_v_self->limit_consumed = 0;

  /* "fastwarc/stream_io.pyx":831
 *         self.limit = strnpos
 *         self.limit_consumed = 0
 *         self.stream_is_compressed = isinstance(stream, CompressingStream)             # <<<<<<<<<<<<<<
 *         self.stream_started = False
 *         self.negotiate_stream = negotiate_stream and not self.stream_is_compressed
 */
  __pyx_t_5 = __Pyx_TypeCheck(((PyObject *)__pyx_v_stream), __pyx_ptype_8fastwarc_9stream_io_CompressingStream); 
  __pyx_v_self->stream_is_compressed = __pyx_t_5;

  /* "fastwarc/stream_io.pyx":832
 *         self.limit_consumed = 0
 *         self.stream_is_compressed = isinstance(stream, CompressingStream)
 *         self.stream_started = False             # <<<<<<<<<<<<<<
 *         self.negotiate_stream = negotiate_stream and not self.stream_is_compressed
 * 
 */
  __pyx_v_self->stream_started = 0;

  /* "fastwarc/stream_io.pyx":833
 *         self.stream_is_compressed = isinstance(stream, CompressingStream)
 *         self.stream_started = False
 *         self.negotiate_stream = negotiate_stream and not self.stream_is_compressed             # <<<<<<<<<<<<<<
 * 
 *     # noinspection PyAttributeOutsideInit
 */
  __pyx_t_6 = (__pyx_v_negotiate_stream != 0);
  if (__pyx_t_6) {
  } else {
    __pyx_t_5 = __pyx_t_6;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_6 = ((!(__pyx_v_self->stream_is_compressed != 0)) != 0);
  __pyx_t_5 = __pyx_t_6;
  __pyx_L3_bool_binop_done:;
  __pyx_v_self->negotiate_stream = __pyx_t_5;

  /* "fastwarc/stream_io.pyx":823
 *         pass
 * 
 *     def __cinit__(self, IOStream stream, size_t buf_size=65536, bint negotiate_stream=True):             # <<<<<<<<<<<<<<
 *         self.stream = stream
 *         self.buf = string()
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":836
 * 
 *     # noinspection PyAttributeOutsideInit
 *     cdef bint detect_stream_type(self) except 0:             # <<<<<<<<<<<<<<
 *         """
 *         Try to auto-detect stream type (GZip, LZ4, or uncompressed).
 */

static int __pyx_f_8fastwarc_9stream_io_14BufferedReader_detect_stream_type(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("detect_stream_type", 0);

  /* "fastwarc/stream_io.pyx":840
 *         Try to auto-detect stream type (GZip, LZ4, or uncompressed).
 *         """
 *         if not self.negotiate_stream or self.stream_started:             # <<<<<<<<<<<<<<
 *             return True
 * 
 */
  __pyx_t_2 = ((!(__pyx_v_self->negotiate_stream != 0)) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = (__pyx_v_self->stream_started != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":841
 *         """
 *         if not self.negotiate_stream or self.stream_started:
 *             return True             # <<<<<<<<<<<<<<
 * 
 *         self.negotiate_stream = False
 */
    __pyx_r = 1;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":840
 *         Try to auto-detect stream type (GZip, LZ4, or uncompressed).
 *         """
 *         if not self.negotiate_stream or self.stream_started:             # <<<<<<<<<<<<<<
 *             return True
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":843
 *             return True
 * 
 *         self.negotiate_stream = False             # <<<<<<<<<<<<<<
 *         self._fill_buf()
 * 
 */
  __pyx_v_self->negotiate_stream = 0;

  /* "fastwarc/stream_io.pyx":844
 * 
 *         self.negotiate_stream = False
 *         self._fill_buf()             # <<<<<<<<<<<<<<
 * 
 *         if self.buf_view.size() > 2 and self.buf_view[0] == <char>0x1f and self.buf_view[1] == <char>0x8b:
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self->__pyx_vtab)->_fill_buf(__pyx_v_self); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(1, 844, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":846
 *         self._fill_buf()
 * 
 *         if self.buf_view.size() > 2 and self.buf_view[0] == <char>0x1f and self.buf_view[1] == <char>0x8b:             # <<<<<<<<<<<<<<
 *             self.stream = GZipStream.__new__(GZipStream, self.stream)
 *             (<GZipStream> self.stream).prepopulate(False, <string>self.buf_view)
 */
  __pyx_t_2 = ((__pyx_v_self->buf_view.size() > 2) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_2 = (((__pyx_v_self->buf_view[0]) == ((char)0x1f)) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_2 = (((__pyx_v_self->buf_view[1]) == ((char)0x8b)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L7_bool_binop_done:;
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":847
 * 
 *         if self.buf_view.size() > 2 and self.buf_view[0] == <char>0x1f and self.buf_view[1] == <char>0x8b:
 *             self.stream = GZipStream.__new__(GZipStream, self.stream)             # <<<<<<<<<<<<<<
 *             (<GZipStream> self.stream).prepopulate(False, <string>self.buf_view)
 *         elif self.buf_view.size() > 4 and memcmp(self.buf_view.data(), <const char*>b'\x04\x22\x4d\x18', 4) == 0:
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 847, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(((PyObject *)__pyx_v_self->stream));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self->stream));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->stream));
    __pyx_t_4 = ((PyObject *)__pyx_tp_new_8fastwarc_9stream_io_GZipStream(((PyTypeObject *)__pyx_ptype_8fastwarc_9stream_io_GZipStream), __pyx_t_3, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 847, __pyx_L1_error)
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(__Pyx_TypeTest(((PyObject *)__pyx_t_4), __pyx_ptype_8fastwarc_9stream_io_IOStream)))) __PYX_ERR(1, 847, __pyx_L1_error)
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_GOTREF(__pyx_v_self->stream);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->stream));
    __pyx_v_self->stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "fastwarc/stream_io.pyx":848
 *         if self.buf_view.size() > 2 and self.buf_view[0] == <char>0x1f and self.buf_view[1] == <char>0x8b:
 *             self.stream = GZipStream.__new__(GZipStream, self.stream)
 *             (<GZipStream> self.stream).prepopulate(False, <string>self.buf_view)             # <<<<<<<<<<<<<<
 *         elif self.buf_view.size() > 4 and memcmp(self.buf_view.data(), <const char*>b'\x04\x22\x4d\x18', 4) == 0:
 *             self.stream = LZ4Stream.__new__(LZ4Stream, self.stream)
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream *)((struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->stream)->__pyx_base.__pyx_base.__pyx_vtab)->prepopulate(((struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)__pyx_v_self->stream), 0, ((std::string)__pyx_v_self->buf_view));

    /* "fastwarc/stream_io.pyx":846
 *         self._fill_buf()
 * 
 *         if self.buf_view.size() > 2 and self.buf_view[0] == <char>0x1f and self.buf_view[1] == <char>0x8b:             # <<<<<<<<<<<<<<
 *             self.stream = GZipStream.__new__(GZipStream, self.stream)
 *             (<GZipStream> self.stream).prepopulate(False, <string>self.buf_view)
 */
    goto __pyx_L6;
  }

  /* "fastwarc/stream_io.pyx":849
 *             self.stream = GZipStream.__new__(GZipStream, self.stream)
 *             (<GZipStream> self.stream).prepopulate(False, <string>self.buf_view)
 *         elif self.buf_view.size() > 4 and memcmp(self.buf_view.data(), <const char*>b'\x04\x22\x4d\x18', 4) == 0:             # <<<<<<<<<<<<<<
 *             self.stream = LZ4Stream.__new__(LZ4Stream, self.stream)
 *             (<LZ4Stream> self.stream).prepopulate(<string>self.buf_view)
 */
  __pyx_t_2 = ((__pyx_v_self->buf_view.size() > 4) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L10_bool_binop_done;
  }
  __pyx_t_2 = ((memcmp(__pyx_v_self->buf_view.data(), ((char const *)((char const *)"\004\"M\030")), 4) == 0) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L10_bool_binop_done:;
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":850
 *             (<GZipStream> self.stream).prepopulate(False, <string>self.buf_view)
 *         elif self.buf_view.size() > 4 and memcmp(self.buf_view.data(), <const char*>b'\x04\x22\x4d\x18', 4) == 0:
 *             self.stream = LZ4Stream.__new__(LZ4Stream, self.stream)             # <<<<<<<<<<<<<<
 *             (<LZ4Stream> self.stream).prepopulate(<string>self.buf_view)
 *         elif self.buf_view.size() > 5 and memcmp(self.buf_view.data(), <const char*>b'WARC/', 5) == 0:
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 850, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(((PyObject *)__pyx_v_self->stream));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self->stream));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self->stream));
    __pyx_t_3 = ((PyObject *)__pyx_tp_new_8fastwarc_9stream_io_LZ4Stream(((PyTypeObject *)__pyx_ptype_8fastwarc_9stream_io_LZ4Stream), __pyx_t_4, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 850, __pyx_L1_error)
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(__Pyx_TypeTest(((PyObject *)__pyx_t_3), __pyx_ptype_8fastwarc_9stream_io_IOStream)))) __PYX_ERR(1, 850, __pyx_L1_error)
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(__pyx_v_self->stream);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->stream));
    __pyx_v_self->stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "fastwarc/stream_io.pyx":851
 *         elif self.buf_view.size() > 4 and memcmp(self.buf_view.data(), <const char*>b'\x04\x22\x4d\x18', 4) == 0:
 *             self.stream = LZ4Stream.__new__(LZ4Stream, self.stream)
 *             (<LZ4Stream> self.stream).prepopulate(<string>self.buf_view)             # <<<<<<<<<<<<<<
 *         elif self.buf_view.size() > 5 and memcmp(self.buf_view.data(), <const char*>b'WARC/', 5) == 0:
 *             # Stream is uncompressed: bail out, don't mess with buffers
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream *)((struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self->stream)->__pyx_base.__pyx_base.__pyx_vtab)->prepopulate(((struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)__pyx_v_self->stream), ((std::string)__pyx_v_self->buf_view));

    /* "fastwarc/stream_io.pyx":849
 *             self.stream = GZipStream.__new__(GZipStream, self.stream)
 *             (<GZipStream> self.stream).prepopulate(False, <string>self.buf_view)
 *         elif self.buf_view.size() > 4 and memcmp(self.buf_view.data(), <const char*>b'\x04\x22\x4d\x18', 4) == 0:             # <<<<<<<<<<<<<<
 *             self.stream = LZ4Stream.__new__(LZ4Stream, self.stream)
 *             (<LZ4Stream> self.stream).prepopulate(<string>self.buf_view)
 */
    goto __pyx_L6;
  }

  /* "fastwarc/stream_io.pyx":852
 *             self.stream = LZ4Stream.__new__(LZ4Stream, self.stream)
 *             (<LZ4Stream> self.stream).prepopulate(<string>self.buf_view)
 *         elif self.buf_view.size() > 5 and memcmp(self.buf_view.data(), <const char*>b'WARC/', 5) == 0:             # <<<<<<<<<<<<<<
 *             # Stream is uncompressed: bail out, don't mess with buffers
 *             self.stream_is_compressed = False
 */
  __pyx_t_2 = ((__pyx_v_self->buf_view.size() > 5) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L12_bool_binop_done;
  }
  __pyx_t_2 = ((memcmp(__pyx_v_self->buf_view.data(), ((char const *)((char const *)"WARC/")), 5) == 0) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L12_bool_binop_done:;
  if (likely(__pyx_t_1)) {

    /* "fastwarc/stream_io.pyx":854
 *         elif self.buf_view.size() > 5 and memcmp(self.buf_view.data(), <const char*>b'WARC/', 5) == 0:
 *             # Stream is uncompressed: bail out, don't mess with buffers
 *             self.stream_is_compressed = False             # <<<<<<<<<<<<<<
 *             return True
 *         else:
 */
    __pyx_v_self->stream_is_compressed = 0;

    /* "fastwarc/stream_io.pyx":855
 *             # Stream is uncompressed: bail out, don't mess with buffers
 *             self.stream_is_compressed = False
 *             return True             # <<<<<<<<<<<<<<
 *         else:
 *             self.stream_is_compressed = False
 */
    __pyx_r = 1;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":852
 *             self.stream = LZ4Stream.__new__(LZ4Stream, self.stream)
 *             (<LZ4Stream> self.stream).prepopulate(<string>self.buf_view)
 *         elif self.buf_view.size() > 5 and memcmp(self.buf_view.data(), <const char*>b'WARC/', 5) == 0:             # <<<<<<<<<<<<<<
 *             # Stream is uncompressed: bail out, don't mess with buffers
 *             self.stream_is_compressed = False
 */
  }

  /* "fastwarc/stream_io.pyx":857
 *             return True
 *         else:
 *             self.stream_is_compressed = False             # <<<<<<<<<<<<<<
 *             raise StreamError('Not a valid WARC stream')
 * 
 */
  /*else*/ {
    __pyx_v_self->stream_is_compressed = 0;

    /* "fastwarc/stream_io.pyx":858
 *         else:
 *             self.stream_is_compressed = False
 *             raise StreamError('Not a valid WARC stream')             # <<<<<<<<<<<<<<
 * 
 *         self.stream_is_compressed = isinstance(self.stream, CompressingStream)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_StreamError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 858, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_kp_u_Not_a_valid_WARC_stream) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_Not_a_valid_WARC_stream);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 858, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 858, __pyx_L1_error)
  }
  __pyx_L6:;

  /* "fastwarc/stream_io.pyx":860
 *             raise StreamError('Not a valid WARC stream')
 * 
 *         self.stream_is_compressed = isinstance(self.stream, CompressingStream)             # <<<<<<<<<<<<<<
 *         self.buf_view.remove_prefix(self.buf_view.size())
 *         self.stream_started = False
 */
  __pyx_t_3 = ((PyObject *)__pyx_v_self->stream);
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_t_3, __pyx_ptype_8fastwarc_9stream_io_CompressingStream); 
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_self->stream_is_compressed = __pyx_t_1;

  /* "fastwarc/stream_io.pyx":861
 * 
 *         self.stream_is_compressed = isinstance(self.stream, CompressingStream)
 *         self.buf_view.remove_prefix(self.buf_view.size())             # <<<<<<<<<<<<<<
 *         self.stream_started = False
 *         return True
 */
  (void)(__pyx_v_self->buf_view.remove_prefix(__pyx_v_self->buf_view.size()));

  /* "fastwarc/stream_io.pyx":862
 *         self.stream_is_compressed = isinstance(self.stream, CompressingStream)
 *         self.buf_view.remove_prefix(self.buf_view.size())
 *         self.stream_started = False             # <<<<<<<<<<<<<<
 *         return True
 * 
 */
  __pyx_v_self->stream_started = 0;

  /* "fastwarc/stream_io.pyx":863
 *         self.buf_view.remove_prefix(self.buf_view.size())
 *         self.stream_started = False
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     cdef bint _fill_buf(self) except -1:
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":836
 * 
 *     # noinspection PyAttributeOutsideInit
 *     cdef bint detect_stream_type(self) except 0:             # <<<<<<<<<<<<<<
 *         """
 *         Try to auto-detect stream type (GZip, LZ4, or uncompressed).
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.detect_stream_type", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":865
 *         return True
 * 
 *     cdef bint _fill_buf(self) except -1:             # <<<<<<<<<<<<<<
 *         """
 *         Refill internal buffer.
 */

static int __pyx_f_8fastwarc_9stream_io_14BufferedReader__fill_buf(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self) {
  size_t __pyx_v_bytes_read;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  size_t __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_fill_buf", 0);

  /* "fastwarc/stream_io.pyx":871
 *         :return: ``True`` if refill was successful, ``False`` otherwise (EOF)
 *         """
 *         self.stream_started = True             # <<<<<<<<<<<<<<
 *         if self.buf_view.size() > 0:
 *             return True if self.limit == strnpos else self.limit > self.limit_consumed
 */
  __pyx_v_self->stream_started = 1;

  /* "fastwarc/stream_io.pyx":872
 *         """
 *         self.stream_started = True
 *         if self.buf_view.size() > 0:             # <<<<<<<<<<<<<<
 *             return True if self.limit == strnpos else self.limit > self.limit_consumed
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->buf_view.size() > 0) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":873
 *         self.stream_started = True
 *         if self.buf_view.size() > 0:
 *             return True if self.limit == strnpos else self.limit > self.limit_consumed             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t bytes_read = self.stream.read(self.buf.data(), self.buf.size())
 */
    if (((__pyx_v_self->limit == std::string::npos) != 0)) {
      __pyx_t_1 = 1;
    } else {
      __pyx_t_1 = (__pyx_v_self->limit > __pyx_v_self->limit_consumed);
    }
    __pyx_r = __pyx_t_1;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":872
 *         """
 *         self.stream_started = True
 *         if self.buf_view.size() > 0:             # <<<<<<<<<<<<<<
 *             return True if self.limit == strnpos else self.limit > self.limit_consumed
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":875
 *             return True if self.limit == strnpos else self.limit > self.limit_consumed
 * 
 *         cdef size_t bytes_read = self.stream.read(self.buf.data(), self.buf.size())             # <<<<<<<<<<<<<<
 *         self.buf_view = string_view(self.buf.data(), bytes_read)
 * 
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->stream->__pyx_vtab)->read(__pyx_v_self->stream, __pyx_v_self->buf.data(), __pyx_v_self->buf.size()); if (unlikely(__pyx_t_2 == ((size_t)-1L))) __PYX_ERR(1, 875, __pyx_L1_error)
  __pyx_v_bytes_read = __pyx_t_2;

  /* "fastwarc/stream_io.pyx":876
 * 
 *         cdef size_t bytes_read = self.stream.read(self.buf.data(), self.buf.size())
 *         self.buf_view = string_view(self.buf.data(), bytes_read)             # <<<<<<<<<<<<<<
 * 
 *         if self.buf_view.size() == 0:
 */
  __pyx_v_self->buf_view = std::string_view(__pyx_v_self->buf.data(), __pyx_v_bytes_read);

  /* "fastwarc/stream_io.pyx":878
 *         self.buf_view = string_view(self.buf.data(), bytes_read)
 * 
 *         if self.buf_view.size() == 0:             # <<<<<<<<<<<<<<
 *             return False
 *         elif self.limit != strnpos:
 */
  __pyx_t_1 = ((__pyx_v_self->buf_view.size() == 0) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":879
 * 
 *         if self.buf_view.size() == 0:
 *             return False             # <<<<<<<<<<<<<<
 *         elif self.limit != strnpos:
 *             return self.limit > self.limit_consumed
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":878
 *         self.buf_view = string_view(self.buf.data(), bytes_read)
 * 
 *         if self.buf_view.size() == 0:             # <<<<<<<<<<<<<<
 *             return False
 *         elif self.limit != strnpos:
 */
  }

  /* "fastwarc/stream_io.pyx":880
 *         if self.buf_view.size() == 0:
 *             return False
 *         elif self.limit != strnpos:             # <<<<<<<<<<<<<<
 *             return self.limit > self.limit_consumed
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->limit != std::string::npos) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":881
 *             return False
 *         elif self.limit != strnpos:
 *             return self.limit > self.limit_consumed             # <<<<<<<<<<<<<<
 * 
 *         return True
 */
    __pyx_r = (__pyx_v_self->limit > __pyx_v_self->limit_consumed);
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":880
 *         if self.buf_view.size() == 0:
 *             return False
 *         elif self.limit != strnpos:             # <<<<<<<<<<<<<<
 *             return self.limit > self.limit_consumed
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":883
 *             return self.limit > self.limit_consumed
 * 
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     cdef string_view* _get_buf(self) nogil:
 */
  __pyx_r = 1;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":865
 *         return True
 * 
 *     cdef bint _fill_buf(self) except -1:             # <<<<<<<<<<<<<<
 *         """
 *         Refill internal buffer.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader._fill_buf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":885
 *         return True
 * 
 *     cdef string_view* _get_buf(self) nogil:             # <<<<<<<<<<<<<<
 *         """
 *         Get buffer contents. Does take a set limit into account.
 */

static CYTHON_INLINE std::string_view *__pyx_f_8fastwarc_9stream_io_14BufferedReader__get_buf(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self) {
  size_t __pyx_v_remaining;
  std::string_view *__pyx_r;
  int __pyx_t_1;

  /* "fastwarc/stream_io.pyx":893
 *         :return: available buffer contents
 *         """
 *         if self.limit == strnpos:             # <<<<<<<<<<<<<<
 *             return &self.buf_view
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->limit == std::string::npos) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":894
 *         """
 *         if self.limit == strnpos:
 *             return &self.buf_view             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t remaining = self.limit - self.limit_consumed
 */
    __pyx_r = (&__pyx_v_self->buf_view);
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":893
 *         :return: available buffer contents
 *         """
 *         if self.limit == strnpos:             # <<<<<<<<<<<<<<
 *             return &self.buf_view
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":896
 *             return &self.buf_view
 * 
 *         cdef size_t remaining = self.limit - self.limit_consumed             # <<<<<<<<<<<<<<
 *         self.limited_buf_view = string_view(self.buf_view.data(), self.buf_view.size())
 *         if self.limited_buf_view.size() > remaining:
 */
  __pyx_v_remaining = (__pyx_v_self->limit - __pyx_v_self->limit_consumed);

  /* "fastwarc/stream_io.pyx":897
 * 
 *         cdef size_t remaining = self.limit - self.limit_consumed
 *         self.limited_buf_view = string_view(self.buf_view.data(), self.buf_view.size())             # <<<<<<<<<<<<<<
 *         if self.limited_buf_view.size() > remaining:
 *             self.limited_buf_view.remove_suffix(self.limited_buf_view.size() - remaining)
 */
  __pyx_v_self->limited_buf_view = std::string_view(__pyx_v_self->buf_view.data(), __pyx_v_self->buf_view.size());

  /* "fastwarc/stream_io.pyx":898
 *         cdef size_t remaining = self.limit - self.limit_consumed
 *         self.limited_buf_view = string_view(self.buf_view.data(), self.buf_view.size())
 *         if self.limited_buf_view.size() > remaining:             # <<<<<<<<<<<<<<
 *             self.limited_buf_view.remove_suffix(self.limited_buf_view.size() - remaining)
 *         return &self.limited_buf_view
 */
  __pyx_t_1 = ((__pyx_v_self->limited_buf_view.size() > __pyx_v_remaining) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":899
 *         self.limited_buf_view = string_view(self.buf_view.data(), self.buf_view.size())
 *         if self.limited_buf_view.size() > remaining:
 *             self.limited_buf_view.remove_suffix(self.limited_buf_view.size() - remaining)             # <<<<<<<<<<<<<<
 *         return &self.limited_buf_view
 * 
 */
    (void)(__pyx_v_self->limited_buf_view.remove_suffix((__pyx_v_self->limited_buf_view.size() - __pyx_v_remaining)));

    /* "fastwarc/stream_io.pyx":898
 *         cdef size_t remaining = self.limit - self.limit_consumed
 *         self.limited_buf_view = string_view(self.buf_view.data(), self.buf_view.size())
 *         if self.limited_buf_view.size() > remaining:             # <<<<<<<<<<<<<<
 *             self.limited_buf_view.remove_suffix(self.limited_buf_view.size() - remaining)
 *         return &self.limited_buf_view
 */
  }

  /* "fastwarc/stream_io.pyx":900
 *         if self.limited_buf_view.size() > remaining:
 *             self.limited_buf_view.remove_suffix(self.limited_buf_view.size() - remaining)
 *         return &self.limited_buf_view             # <<<<<<<<<<<<<<
 * 
 *     cdef size_t _consume_buf(self, size_t size) nogil:
 */
  __pyx_r = (&__pyx_v_self->limited_buf_view);
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":885
 *         return True
 * 
 *     cdef string_view* _get_buf(self) nogil:             # <<<<<<<<<<<<<<
 *         """
 *         Get buffer contents. Does take a set limit into account.
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":902
 *         return &self.limited_buf_view
 * 
 *     cdef size_t _consume_buf(self, size_t size) nogil:             # <<<<<<<<<<<<<<
 *         """
 *         Consume up to ``size`` bytes from internal buffer. Takes a set limit into account.
 */

static CYTHON_INLINE size_t __pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, size_t __pyx_v_size) {
  size_t __pyx_v_consumed;
  size_t __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;

  /* "fastwarc/stream_io.pyx":910
 *         """
 *         cdef size_t consumed
 *         if self.limit == strnpos and size >= self.buf_view.size():             # <<<<<<<<<<<<<<
 *             consumed = self.buf_view.size()
 *             self.buf_view.remove_prefix(consumed)
 */
  __pyx_t_2 = ((__pyx_v_self->limit == std::string::npos) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = ((__pyx_v_size >= __pyx_v_self->buf_view.size()) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":911
 *         cdef size_t consumed
 *         if self.limit == strnpos and size >= self.buf_view.size():
 *             consumed = self.buf_view.size()             # <<<<<<<<<<<<<<
 *             self.buf_view.remove_prefix(consumed)
 *             return consumed
 */
    __pyx_v_consumed = __pyx_v_self->buf_view.size();

    /* "fastwarc/stream_io.pyx":912
 *         if self.limit == strnpos and size >= self.buf_view.size():
 *             consumed = self.buf_view.size()
 *             self.buf_view.remove_prefix(consumed)             # <<<<<<<<<<<<<<
 *             return consumed
 * 
 */
    (void)(__pyx_v_self->buf_view.remove_prefix(__pyx_v_consumed));

    /* "fastwarc/stream_io.pyx":913
 *             consumed = self.buf_view.size()
 *             self.buf_view.remove_prefix(consumed)
 *             return consumed             # <<<<<<<<<<<<<<
 * 
 *         if self.limit != strnpos:
 */
    __pyx_r = __pyx_v_consumed;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":910
 *         """
 *         cdef size_t consumed
 *         if self.limit == strnpos and size >= self.buf_view.size():             # <<<<<<<<<<<<<<
 *             consumed = self.buf_view.size()
 *             self.buf_view.remove_prefix(consumed)
 */
  }

  /* "fastwarc/stream_io.pyx":915
 *             return consumed
 * 
 *         if self.limit != strnpos:             # <<<<<<<<<<<<<<
 *             if size > self.limit - self.limit_consumed:
 *                 size = self.limit - self.limit_consumed
 */
  __pyx_t_1 = ((__pyx_v_self->limit != std::string::npos) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":916
 * 
 *         if self.limit != strnpos:
 *             if size > self.limit - self.limit_consumed:             # <<<<<<<<<<<<<<
 *                 size = self.limit - self.limit_consumed
 *             self.limit_consumed += size
 */
    __pyx_t_1 = ((__pyx_v_size > (__pyx_v_self->limit - __pyx_v_self->limit_consumed)) != 0);
    if (__pyx_t_1) {

      /* "fastwarc/stream_io.pyx":917
 *         if self.limit != strnpos:
 *             if size > self.limit - self.limit_consumed:
 *                 size = self.limit - self.limit_consumed             # <<<<<<<<<<<<<<
 *             self.limit_consumed += size
 * 
 */
      __pyx_v_size = (__pyx_v_self->limit - __pyx_v_self->limit_consumed);

      /* "fastwarc/stream_io.pyx":916
 * 
 *         if self.limit != strnpos:
 *             if size > self.limit - self.limit_consumed:             # <<<<<<<<<<<<<<
 *                 size = self.limit - self.limit_consumed
 *             self.limit_consumed += size
 */
    }

    /* "fastwarc/stream_io.pyx":918
 *             if size > self.limit - self.limit_consumed:
 *                 size = self.limit - self.limit_consumed
 *             self.limit_consumed += size             # <<<<<<<<<<<<<<
 * 
 *         if size > self.buf_view.size():
 */
    __pyx_v_self->limit_consumed = (__pyx_v_self->limit_consumed + __pyx_v_size);

    /* "fastwarc/stream_io.pyx":915
 *             return consumed
 * 
 *         if self.limit != strnpos:             # <<<<<<<<<<<<<<
 *             if size > self.limit - self.limit_consumed:
 *                 size = self.limit - self.limit_consumed
 */
  }

  /* "fastwarc/stream_io.pyx":920
 *             self.limit_consumed += size
 * 
 *         if size > self.buf_view.size():             # <<<<<<<<<<<<<<
 *             size = self.buf_view.size()
 *         self.buf_view.remove_prefix(size)
 */
  __pyx_t_1 = ((__pyx_v_size > __pyx_v_self->buf_view.size()) != 0);
  if (__pyx_t_1) {

    /* "fastwarc/stream_io.pyx":921
 * 
 *         if size > self.buf_view.size():
 *             size = self.buf_view.size()             # <<<<<<<<<<<<<<
 *         self.buf_view.remove_prefix(size)
 *         return size
 */
    __pyx_v_size = __pyx_v_self->buf_view.size();

    /* "fastwarc/stream_io.pyx":920
 *             self.limit_consumed += size
 * 
 *         if size > self.buf_view.size():             # <<<<<<<<<<<<<<
 *             size = self.buf_view.size()
 *         self.buf_view.remove_prefix(size)
 */
  }

  /* "fastwarc/stream_io.pyx":922
 *         if size > self.buf_view.size():
 *             size = self.buf_view.size()
 *         self.buf_view.remove_prefix(size)             # <<<<<<<<<<<<<<
 *         return size
 * 
 */
  (void)(__pyx_v_self->buf_view.remove_prefix(__pyx_v_size));

  /* "fastwarc/stream_io.pyx":923
 *             size = self.buf_view.size()
 *         self.buf_view.remove_prefix(size)
 *         return size             # <<<<<<<<<<<<<<
 * 
 *     cdef inline void set_limit(self, size_t offset) nogil:
 */
  __pyx_r = __pyx_v_size;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":902
 *         return &self.limited_buf_view
 * 
 *     cdef size_t _consume_buf(self, size_t size) nogil:             # <<<<<<<<<<<<<<
 *         """
 *         Consume up to ``size`` bytes from internal buffer. Takes a set limit into account.
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":925
 *         return size
 * 
 *     cdef inline void set_limit(self, size_t offset) nogil:             # <<<<<<<<<<<<<<
 *         """
 *         Set a stream limit in bytes. Any read beyond this limit will act as if the stream reached EOF.
 */

static CYTHON_INLINE void __pyx_f_8fastwarc_9stream_io_14BufferedReader_set_limit(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, size_t __pyx_v_offset) {

  /* "fastwarc/stream_io.pyx":932
 *         :param offset: limit in bytes
 *         """
 *         self.limit = offset             # <<<<<<<<<<<<<<
 *         self.limit_consumed = 0
 * 
 */
  __pyx_v_self->limit = __pyx_v_offset;

  /* "fastwarc/stream_io.pyx":933
 *         """
 *         self.limit = offset
 *         self.limit_consumed = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef inline void reset_limit(self) nogil:
 */
  __pyx_v_self->limit_consumed = 0;

  /* "fastwarc/stream_io.pyx":925
 *         return size
 * 
 *     cdef inline void set_limit(self, size_t offset) nogil:             # <<<<<<<<<<<<<<
 *         """
 *         Set a stream limit in bytes. Any read beyond this limit will act as if the stream reached EOF.
 */

  /* function exit code */
}

/* "fastwarc/stream_io.pyx":935
 *         self.limit_consumed = 0
 * 
 *     cdef inline void reset_limit(self) nogil:             # <<<<<<<<<<<<<<
 *         """Reset any previously set stream limit."""
 *         self.limit = strnpos
 */

static CYTHON_INLINE void __pyx_f_8fastwarc_9stream_io_14BufferedReader_reset_limit(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self) {

  /* "fastwarc/stream_io.pyx":937
 *     cdef inline void reset_limit(self) nogil:
 *         """Reset any previously set stream limit."""
 *         self.limit = strnpos             # <<<<<<<<<<<<<<
 * 
 *     cpdef string read(self, size_t size=strnpos) except *:
 */
  __pyx_v_self->limit = std::string::npos;

  /* "fastwarc/stream_io.pyx":935
 *         self.limit_consumed = 0
 * 
 *     cdef inline void reset_limit(self) nogil:             # <<<<<<<<<<<<<<
 *         """Reset any previously set stream limit."""
 *         self.limit = strnpos
 */

  /* function exit code */
}

/* "fastwarc/stream_io.pyx":939
 *         self.limit = strnpos
 * 
 *     cpdef string read(self, size_t size=strnpos) except *:             # <<<<<<<<<<<<<<
 *         """
 *         read(self, size=-1)
 */

static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_5read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static std::string __pyx_f_8fastwarc_9stream_io_14BufferedReader_read(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_read *__pyx_optional_args) {
  size_t __pyx_v_size = __pyx_k__4;
  std::string __pyx_v_data_read;
  size_t __pyx_v_remaining;
  std::string_view __pyx_v_buf_sub;
  CYTHON_UNUSED std::string_view *__pyx_v_buf;
  std::string __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  std::string __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("read", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_size = __pyx_optional_args->size;
    }
  }
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 939, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_5read)) {
        __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 939, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
          }
        }
        __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 939, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_6 = __pyx_convert_string_from_py_std__in_string(__pyx_t_2); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 939, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_6;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "fastwarc/stream_io.pyx":951
 *         """
 *         cdef string data_read
 *         cdef size_t remaining = size             # <<<<<<<<<<<<<<
 *         cdef string_view buf_sub
 * 
 */
  __pyx_v_remaining = __pyx_v_size;

  /* "fastwarc/stream_io.pyx":954
 *         cdef string_view buf_sub
 * 
 *         while (size == strnpos or data_read.size() < size) and self._fill_buf():             # <<<<<<<<<<<<<<
 *             buf = self._get_buf()
 *             remaining = size - data_read.size()
 */
  while (1) {
    __pyx_t_8 = ((__pyx_v_size == std::string::npos) != 0);
    if (!__pyx_t_8) {
    } else {
      goto __pyx_L6_next_and;
    }
    __pyx_t_8 = ((__pyx_v_data_read.size() < __pyx_v_size) != 0);
    if (__pyx_t_8) {
    } else {
      __pyx_t_7 = __pyx_t_8;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_L6_next_and:;
    __pyx_t_8 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self->__pyx_vtab)->_fill_buf(__pyx_v_self); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(1, 954, __pyx_L1_error)
    __pyx_t_9 = (__pyx_t_8 != 0);
    __pyx_t_7 = __pyx_t_9;
    __pyx_L5_bool_binop_done:;
    if (!__pyx_t_7) break;

    /* "fastwarc/stream_io.pyx":955
 * 
 *         while (size == strnpos or data_read.size() < size) and self._fill_buf():
 *             buf = self._get_buf()             # <<<<<<<<<<<<<<
 *             remaining = size - data_read.size()
 *             buf_sub = self._get_buf().substr(0, remaining)
 */
    __pyx_v_buf = __pyx_f_8fastwarc_9stream_io_14BufferedReader__get_buf(__pyx_v_self);

    /* "fastwarc/stream_io.pyx":956
 *         while (size == strnpos or data_read.size() < size) and self._fill_buf():
 *             buf = self._get_buf()
 *             remaining = size - data_read.size()             # <<<<<<<<<<<<<<
 *             buf_sub = self._get_buf().substr(0, remaining)
 *             data_read.append(buf_sub.data(), buf_sub.size())
 */
    __pyx_v_remaining = (__pyx_v_size - __pyx_v_data_read.size());

    /* "fastwarc/stream_io.pyx":957
 *             buf = self._get_buf()
 *             remaining = size - data_read.size()
 *             buf_sub = self._get_buf().substr(0, remaining)             # <<<<<<<<<<<<<<
 *             data_read.append(buf_sub.data(), buf_sub.size())
 *             self._consume_buf(buf_sub.size())
 */
    __pyx_v_buf_sub = __pyx_f_8fastwarc_9stream_io_14BufferedReader__get_buf(__pyx_v_self)->substr(0, __pyx_v_remaining);

    /* "fastwarc/stream_io.pyx":958
 *             remaining = size - data_read.size()
 *             buf_sub = self._get_buf().substr(0, remaining)
 *             data_read.append(buf_sub.data(), buf_sub.size())             # <<<<<<<<<<<<<<
 *             self._consume_buf(buf_sub.size())
 *         return data_read
 */
    try {
      __pyx_v_data_read.append(__pyx_v_buf_sub.data(), __pyx_v_buf_sub.size());
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 958, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":959
 *             buf_sub = self._get_buf().substr(0, remaining)
 *             data_read.append(buf_sub.data(), buf_sub.size())
 *             self._consume_buf(buf_sub.size())             # <<<<<<<<<<<<<<
 *         return data_read
 * 
 */
    (void)(__pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf(__pyx_v_self, __pyx_v_buf_sub.size()));
  }

  /* "fastwarc/stream_io.pyx":960
 *             data_read.append(buf_sub.data(), buf_sub.size())
 *             self._consume_buf(buf_sub.size())
 *         return data_read             # <<<<<<<<<<<<<<
 * 
 *     cpdef string readline(self, bint crlf=True, size_t max_line_len=8192) except *:
 */
  __pyx_r = __pyx_v_data_read;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":939
 *         self.limit = strnpos
 * 
 *     cpdef string read(self, size_t size=strnpos) except *:             # <<<<<<<<<<<<<<
 *         """
 *         read(self, size=-1)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_pretend_to_initialize(&__pyx_r);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_5read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_14BufferedReader_4read[] = "\n        read(self, size=-1)\n        \n        Read up to ``size`` bytes from the input stream.\n        \n        :param size: number of bytes to read (default means read remaining stream)\n        :type size: int\n        :return: consumed buffer contents as bytes (or empty string if EOF)\n        :rtype: bytes\n        ";
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_5read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  size_t __pyx_v_size;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("read (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_size,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_size);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read") < 0)) __PYX_ERR(1, 939, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    if (values[0]) {
      __pyx_v_size = __Pyx_PyInt_As_size_t(values[0]); if (unlikely((__pyx_v_size == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 939, __pyx_L3_error)
    } else {
      __pyx_v_size = __pyx_k__4;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 939, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_14BufferedReader_4read(((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self), __pyx_v_size);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_4read(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, size_t __pyx_v_size) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  std::string __pyx_t_1;
  struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_read __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("read", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.size = __pyx_v_size;
  __pyx_t_1 = __pyx_vtabptr_8fastwarc_9stream_io_BufferedReader->read(__pyx_v_self, 1, &__pyx_t_2); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 939, __pyx_L1_error)
  __pyx_t_3 = __pyx_convert_PyBytes_string_to_py_std__in_string(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 939, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":962
 *         return data_read
 * 
 *     cpdef string readline(self, bint crlf=True, size_t max_line_len=8192) except *:             # <<<<<<<<<<<<<<
 *         """
 *         readline(self, crlf=True, max_line_len=8192)
 */

static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_7readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static std::string __pyx_f_8fastwarc_9stream_io_14BufferedReader_readline(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_readline *__pyx_optional_args) {
  int __pyx_v_crlf = ((int)1);
  size_t __pyx_v_max_line_len = ((size_t)0x2000);
  std::string_view *__pyx_v_buf;
  size_t __pyx_v_capacity_remaining;
  int __pyx_v_last_was_cr;
  std::string __pyx_v_line;
  size_t __pyx_v_lf_pos;
  char *__pyx_v_lf_ptr;
  std::string __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  std::string __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  size_t __pyx_t_13;
  size_t __pyx_t_14;
  size_t __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("readline", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_crlf = __pyx_optional_args->crlf;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_max_line_len = __pyx_optional_args->max_line_len;
      }
    }
  }
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_readline); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 962, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_7readline)) {
        __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_crlf); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 962, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = __Pyx_PyInt_FromSize_t(__pyx_v_max_line_len); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 962, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_5 = __pyx_t_1; __pyx_t_6 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_7 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_4};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 962, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_4};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 962, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        } else
        #endif
        {
          __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 962, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          if (__pyx_t_6) {
            __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_4);
          PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_4);
          __pyx_t_3 = 0;
          __pyx_t_4 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 962, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_9 = __pyx_convert_string_from_py_std__in_string(__pyx_t_2); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 962, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_9;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "fastwarc/stream_io.pyx":978
 * 
 *         cdef string_view* buf
 *         cdef size_t capacity_remaining = max_line_len             # <<<<<<<<<<<<<<
 *         cdef bint last_was_cr = False
 * 
 */
  __pyx_v_capacity_remaining = __pyx_v_max_line_len;

  /* "fastwarc/stream_io.pyx":979
 *         cdef string_view* buf
 *         cdef size_t capacity_remaining = max_line_len
 *         cdef bint last_was_cr = False             # <<<<<<<<<<<<<<
 * 
 *         cdef string line
 */
  __pyx_v_last_was_cr = 0;

  /* "fastwarc/stream_io.pyx":982
 * 
 *         cdef string line
 *         line.reserve(192)             # <<<<<<<<<<<<<<
 * 
 *         cdef size_t lf_pos = 0
 */
  try {
    __pyx_v_line.reserve(0xC0);
  } catch(...) {
    __Pyx_CppExn2PyErr();
    __PYX_ERR(1, 982, __pyx_L1_error)
  }

  /* "fastwarc/stream_io.pyx":984
 *         line.reserve(192)
 * 
 *         cdef size_t lf_pos = 0             # <<<<<<<<<<<<<<
 *         cdef char* lf_ptr = NULL
 * 
 */
  __pyx_v_lf_pos = 0;

  /* "fastwarc/stream_io.pyx":985
 * 
 *         cdef size_t lf_pos = 0
 *         cdef char* lf_ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *         while lf_ptr == NULL and self._fill_buf():
 */
  __pyx_v_lf_ptr = NULL;

  /* "fastwarc/stream_io.pyx":987
 *         cdef char* lf_ptr = NULL
 * 
 *         while lf_ptr == NULL and self._fill_buf():             # <<<<<<<<<<<<<<
 *             buf = self._get_buf()
 * 
 */
  while (1) {
    __pyx_t_11 = ((__pyx_v_lf_ptr == NULL) != 0);
    if (__pyx_t_11) {
    } else {
      __pyx_t_10 = __pyx_t_11;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_t_11 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self->__pyx_vtab)->_fill_buf(__pyx_v_self); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 987, __pyx_L1_error)
    __pyx_t_12 = (__pyx_t_11 != 0);
    __pyx_t_10 = __pyx_t_12;
    __pyx_L5_bool_binop_done:;
    if (!__pyx_t_10) break;

    /* "fastwarc/stream_io.pyx":988
 * 
 *         while lf_ptr == NULL and self._fill_buf():
 *             buf = self._get_buf()             # <<<<<<<<<<<<<<
 * 
 *             if crlf:
 */
    __pyx_v_buf = __pyx_f_8fastwarc_9stream_io_14BufferedReader__get_buf(__pyx_v_self);

    /* "fastwarc/stream_io.pyx":990
 *             buf = self._get_buf()
 * 
 *             if crlf:             # <<<<<<<<<<<<<<
 *                 if last_was_cr and buf.front() == b'\n':
 *                     line.push_back(b'\n')
 */
    __pyx_t_10 = (__pyx_v_crlf != 0);
    if (__pyx_t_10) {

      /* "fastwarc/stream_io.pyx":991
 * 
 *             if crlf:
 *                 if last_was_cr and buf.front() == b'\n':             # <<<<<<<<<<<<<<
 *                     line.push_back(b'\n')
 *                     self._consume_buf(1)
 */
      __pyx_t_12 = (__pyx_v_last_was_cr != 0);
      if (__pyx_t_12) {
      } else {
        __pyx_t_10 = __pyx_t_12;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_12 = ((__pyx_v_buf->front() == '\n') != 0);
      __pyx_t_10 = __pyx_t_12;
      __pyx_L9_bool_binop_done:;
      if (__pyx_t_10) {

        /* "fastwarc/stream_io.pyx":992
 *             if crlf:
 *                 if last_was_cr and buf.front() == b'\n':
 *                     line.push_back(b'\n')             # <<<<<<<<<<<<<<
 *                     self._consume_buf(1)
 *                     return line
 */
        try {
          __pyx_v_line.push_back('\n');
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(1, 992, __pyx_L1_error)
        }

        /* "fastwarc/stream_io.pyx":993
 *                 if last_was_cr and buf.front() == b'\n':
 *                     line.push_back(b'\n')
 *                     self._consume_buf(1)             # <<<<<<<<<<<<<<
 *                     return line
 *                 last_was_cr = False
 */
        (void)(__pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf(__pyx_v_self, 1));

        /* "fastwarc/stream_io.pyx":994
 *                     line.push_back(b'\n')
 *                     self._consume_buf(1)
 *                     return line             # <<<<<<<<<<<<<<
 *                 last_was_cr = False
 * 
 */
        __pyx_r = __pyx_v_line;
        goto __pyx_L0;

        /* "fastwarc/stream_io.pyx":991
 * 
 *             if crlf:
 *                 if last_was_cr and buf.front() == b'\n':             # <<<<<<<<<<<<<<
 *                     line.push_back(b'\n')
 *                     self._consume_buf(1)
 */
      }

      /* "fastwarc/stream_io.pyx":995
 *                     self._consume_buf(1)
 *                     return line
 *                 last_was_cr = False             # <<<<<<<<<<<<<<
 * 
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\r', buf.size())
 */
      __pyx_v_last_was_cr = 0;

      /* "fastwarc/stream_io.pyx":997
 *                 last_was_cr = False
 * 
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\r', buf.size())             # <<<<<<<<<<<<<<
 *                 while lf_ptr != NULL:
 *                     lf_pos = lf_ptr - buf.data() + 1
 */
      __pyx_v_lf_ptr = ((char *)memchr(__pyx_v_buf->data(), ((int)'\r'), __pyx_v_buf->size()));

      /* "fastwarc/stream_io.pyx":998
 * 
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\r', buf.size())
 *                 while lf_ptr != NULL:             # <<<<<<<<<<<<<<
 *                     lf_pos = lf_ptr - buf.data() + 1
 *                     if lf_pos == buf.size():
 */
      while (1) {
        __pyx_t_10 = ((__pyx_v_lf_ptr != NULL) != 0);
        if (!__pyx_t_10) break;

        /* "fastwarc/stream_io.pyx":999
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\r', buf.size())
 *                 while lf_ptr != NULL:
 *                     lf_pos = lf_ptr - buf.data() + 1             # <<<<<<<<<<<<<<
 *                     if lf_pos == buf.size():
 *                         last_was_cr = True
 */
        __pyx_v_lf_pos = ((__pyx_v_lf_ptr - __pyx_v_buf->data()) + 1);

        /* "fastwarc/stream_io.pyx":1000
 *                 while lf_ptr != NULL:
 *                     lf_pos = lf_ptr - buf.data() + 1
 *                     if lf_pos == buf.size():             # <<<<<<<<<<<<<<
 *                         last_was_cr = True
 *                         lf_ptr = NULL
 */
        __pyx_t_10 = ((__pyx_v_lf_pos == __pyx_v_buf->size()) != 0);
        if (__pyx_t_10) {

          /* "fastwarc/stream_io.pyx":1001
 *                     lf_pos = lf_ptr - buf.data() + 1
 *                     if lf_pos == buf.size():
 *                         last_was_cr = True             # <<<<<<<<<<<<<<
 *                         lf_ptr = NULL
 *                         break
 */
          __pyx_v_last_was_cr = 1;

          /* "fastwarc/stream_io.pyx":1002
 *                     if lf_pos == buf.size():
 *                         last_was_cr = True
 *                         lf_ptr = NULL             # <<<<<<<<<<<<<<
 *                         break
 *                     preinc(lf_ptr)
 */
          __pyx_v_lf_ptr = NULL;

          /* "fastwarc/stream_io.pyx":1003
 *                         last_was_cr = True
 *                         lf_ptr = NULL
 *                         break             # <<<<<<<<<<<<<<
 *                     preinc(lf_ptr)
 *                     if lf_ptr[0] == b'\n':
 */
          goto __pyx_L12_break;

          /* "fastwarc/stream_io.pyx":1000
 *                 while lf_ptr != NULL:
 *                     lf_pos = lf_ptr - buf.data() + 1
 *                     if lf_pos == buf.size():             # <<<<<<<<<<<<<<
 *                         last_was_cr = True
 *                         lf_ptr = NULL
 */
        }

        /* "fastwarc/stream_io.pyx":1004
 *                         lf_ptr = NULL
 *                         break
 *                     preinc(lf_ptr)             # <<<<<<<<<<<<<<
 *                     if lf_ptr[0] == b'\n':
 *                         break
 */
        (void)((++__pyx_v_lf_ptr));

        /* "fastwarc/stream_io.pyx":1005
 *                         break
 *                     preinc(lf_ptr)
 *                     if lf_ptr[0] == b'\n':             # <<<<<<<<<<<<<<
 *                         break
 *                     lf_ptr = <char*>memchr(lf_ptr, <int>b'\r', buf.size() - lf_pos)
 */
        __pyx_t_10 = (((__pyx_v_lf_ptr[0]) == '\n') != 0);
        if (__pyx_t_10) {

          /* "fastwarc/stream_io.pyx":1006
 *                     preinc(lf_ptr)
 *                     if lf_ptr[0] == b'\n':
 *                         break             # <<<<<<<<<<<<<<
 *                     lf_ptr = <char*>memchr(lf_ptr, <int>b'\r', buf.size() - lf_pos)
 *             else:
 */
          goto __pyx_L12_break;

          /* "fastwarc/stream_io.pyx":1005
 *                         break
 *                     preinc(lf_ptr)
 *                     if lf_ptr[0] == b'\n':             # <<<<<<<<<<<<<<
 *                         break
 *                     lf_ptr = <char*>memchr(lf_ptr, <int>b'\r', buf.size() - lf_pos)
 */
        }

        /* "fastwarc/stream_io.pyx":1007
 *                     if lf_ptr[0] == b'\n':
 *                         break
 *                     lf_ptr = <char*>memchr(lf_ptr, <int>b'\r', buf.size() - lf_pos)             # <<<<<<<<<<<<<<
 *             else:
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\n', buf.size())
 */
        __pyx_v_lf_ptr = ((char *)memchr(__pyx_v_lf_ptr, ((int)'\r'), (__pyx_v_buf->size() - __pyx_v_lf_pos)));
      }
      __pyx_L12_break:;

      /* "fastwarc/stream_io.pyx":990
 *             buf = self._get_buf()
 * 
 *             if crlf:             # <<<<<<<<<<<<<<
 *                 if last_was_cr and buf.front() == b'\n':
 *                     line.push_back(b'\n')
 */
      goto __pyx_L7;
    }

    /* "fastwarc/stream_io.pyx":1009
 *                     lf_ptr = <char*>memchr(lf_ptr, <int>b'\r', buf.size() - lf_pos)
 *             else:
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\n', buf.size())             # <<<<<<<<<<<<<<
 *                 if lf_ptr != NULL:
 *                     lf_pos = lf_ptr - buf.data()
 */
    /*else*/ {
      __pyx_v_lf_ptr = ((char *)memchr(__pyx_v_buf->data(), ((int)'\n'), __pyx_v_buf->size()));

      /* "fastwarc/stream_io.pyx":1010
 *             else:
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\n', buf.size())
 *                 if lf_ptr != NULL:             # <<<<<<<<<<<<<<
 *                     lf_pos = lf_ptr - buf.data()
 * 
 */
      __pyx_t_10 = ((__pyx_v_lf_ptr != NULL) != 0);
      if (__pyx_t_10) {

        /* "fastwarc/stream_io.pyx":1011
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\n', buf.size())
 *                 if lf_ptr != NULL:
 *                     lf_pos = lf_ptr - buf.data()             # <<<<<<<<<<<<<<
 * 
 *             if lf_ptr == NULL:
 */
        __pyx_v_lf_pos = (__pyx_v_lf_ptr - __pyx_v_buf->data());

        /* "fastwarc/stream_io.pyx":1010
 *             else:
 *                 lf_ptr = <char*>memchr(buf.data(), <int>b'\n', buf.size())
 *                 if lf_ptr != NULL:             # <<<<<<<<<<<<<<
 *                     lf_pos = lf_ptr - buf.data()
 * 
 */
      }
    }
    __pyx_L7:;

    /* "fastwarc/stream_io.pyx":1013
 *                     lf_pos = lf_ptr - buf.data()
 * 
 *             if lf_ptr == NULL:             # <<<<<<<<<<<<<<
 *                 lf_pos = buf.size() - 1
 * 
 */
    __pyx_t_10 = ((__pyx_v_lf_ptr == NULL) != 0);
    if (__pyx_t_10) {

      /* "fastwarc/stream_io.pyx":1014
 * 
 *             if lf_ptr == NULL:
 *                 lf_pos = buf.size() - 1             # <<<<<<<<<<<<<<
 * 
 *             preinc(lf_pos)
 */
      __pyx_v_lf_pos = (__pyx_v_buf->size() - 1);

      /* "fastwarc/stream_io.pyx":1013
 *                     lf_pos = lf_ptr - buf.data()
 * 
 *             if lf_ptr == NULL:             # <<<<<<<<<<<<<<
 *                 lf_pos = buf.size() - 1
 * 
 */
    }

    /* "fastwarc/stream_io.pyx":1016
 *                 lf_pos = buf.size() - 1
 * 
 *             preinc(lf_pos)             # <<<<<<<<<<<<<<
 *             line.append(buf.data(), min(lf_pos, capacity_remaining))
 *             capacity_remaining = max_line_len - line.size()
 */
    (void)((++__pyx_v_lf_pos));

    /* "fastwarc/stream_io.pyx":1017
 * 
 *             preinc(lf_pos)
 *             line.append(buf.data(), min(lf_pos, capacity_remaining))             # <<<<<<<<<<<<<<
 *             capacity_remaining = max_line_len - line.size()
 *             self._consume_buf(lf_pos)
 */
    __pyx_t_13 = __pyx_v_capacity_remaining;
    __pyx_t_14 = __pyx_v_lf_pos;
    if (((__pyx_t_13 < __pyx_t_14) != 0)) {
      __pyx_t_15 = __pyx_t_13;
    } else {
      __pyx_t_15 = __pyx_t_14;
    }
    try {
      __pyx_v_line.append(__pyx_v_buf->data(), __pyx_t_15);
    } catch(...) {
      __Pyx_CppExn2PyErr();
      __PYX_ERR(1, 1017, __pyx_L1_error)
    }

    /* "fastwarc/stream_io.pyx":1018
 *             preinc(lf_pos)
 *             line.append(buf.data(), min(lf_pos, capacity_remaining))
 *             capacity_remaining = max_line_len - line.size()             # <<<<<<<<<<<<<<
 *             self._consume_buf(lf_pos)
 * 
 */
    __pyx_v_capacity_remaining = (__pyx_v_max_line_len - __pyx_v_line.size());

    /* "fastwarc/stream_io.pyx":1019
 *             line.append(buf.data(), min(lf_pos, capacity_remaining))
 *             capacity_remaining = max_line_len - line.size()
 *             self._consume_buf(lf_pos)             # <<<<<<<<<<<<<<
 * 
 *         return line
 */
    (void)(__pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf(__pyx_v_self, __pyx_v_lf_pos));
  }

  /* "fastwarc/stream_io.pyx":1021
 *             self._consume_buf(lf_pos)
 * 
 *         return line             # <<<<<<<<<<<<<<
 * 
 *     cpdef size_t tell(self) except -1:
 */
  __pyx_r = __pyx_v_line;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":962
 *         return data_read
 * 
 *     cpdef string readline(self, bint crlf=True, size_t max_line_len=8192) except *:             # <<<<<<<<<<<<<<
 *         """
 *         readline(self, crlf=True, max_line_len=8192)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.readline", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_pretend_to_initialize(&__pyx_r);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_7readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_14BufferedReader_6readline[] = "\n        readline(self, crlf=True, max_line_len=8192)\n        \n        Read a single line from the input stream.\n        \n        :param crlf: whether lines are separated by CRLF or LF\n        :type crlf: bool\n        :param max_line_len: maximum line length (longer lines will still be consumed, but the return\n                             value will not be larger than this)\n        :type max_line_len: int\n        :return: line contents (or empty string if EOF)\n        :rtype: bytes\n        ";
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_7readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_crlf;
  size_t __pyx_v_max_line_len;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("readline (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_crlf,&__pyx_n_s_max_line_len,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_crlf);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_line_len);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "readline") < 0)) __PYX_ERR(1, 962, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    if (values[0]) {
      __pyx_v_crlf = __Pyx_PyObject_IsTrue(values[0]); if (unlikely((__pyx_v_crlf == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 962, __pyx_L3_error)
    } else {
      __pyx_v_crlf = ((int)1);
    }
    if (values[1]) {
      __pyx_v_max_line_len = __Pyx_PyInt_As_size_t(values[1]); if (unlikely((__pyx_v_max_line_len == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 962, __pyx_L3_error)
    } else {
      __pyx_v_max_line_len = ((size_t)0x2000);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("readline", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 962, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.readline", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_14BufferedReader_6readline(((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self), __pyx_v_crlf, __pyx_v_max_line_len);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_6readline(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_v_crlf, size_t __pyx_v_max_line_len) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  std::string __pyx_t_1;
  struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_readline __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("readline", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.crlf = __pyx_v_crlf;
  __pyx_t_2.max_line_len = __pyx_v_max_line_len;
  __pyx_t_1 = __pyx_vtabptr_8fastwarc_9stream_io_BufferedReader->readline(__pyx_v_self, 1, &__pyx_t_2); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 962, __pyx_L1_error)
  __pyx_t_3 = __pyx_convert_PyBytes_string_to_py_std__in_string(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 962, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.readline", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":1023
 *         return line
 * 
 *     cpdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         """
 *         tell(self)
 */

static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_9tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static size_t __pyx_f_8fastwarc_9stream_io_14BufferedReader_tell(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  size_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("tell", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1023, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_9tell)) {
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1023, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_5 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_5 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 1023, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_5;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "fastwarc/stream_io.pyx":1032
 *         :rtype: int
 *         """
 *         if not self.stream_is_compressed and not self.stream_started:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_7 = ((!(__pyx_v_self->stream_is_compressed != 0)) != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_6 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_7 = ((!(__pyx_v_self->stream_started != 0)) != 0);
  __pyx_t_6 = __pyx_t_7;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_6) {

    /* "fastwarc/stream_io.pyx":1033
 *         """
 *         if not self.stream_is_compressed and not self.stream_started:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if self.limit != strnpos:
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":1032
 *         :rtype: int
 *         """
 *         if not self.stream_is_compressed and not self.stream_started:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":1035
 *             return 0
 * 
 *         if self.limit != strnpos:             # <<<<<<<<<<<<<<
 *             return self.limit_consumed
 * 
 */
  __pyx_t_6 = ((__pyx_v_self->limit != std::string::npos) != 0);
  if (__pyx_t_6) {

    /* "fastwarc/stream_io.pyx":1036
 * 
 *         if self.limit != strnpos:
 *             return self.limit_consumed             # <<<<<<<<<<<<<<
 * 
 *         if self.stream_is_compressed:
 */
    __pyx_r = __pyx_v_self->limit_consumed;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":1035
 *             return 0
 * 
 *         if self.limit != strnpos:             # <<<<<<<<<<<<<<
 *             return self.limit_consumed
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":1038
 *             return self.limit_consumed
 * 
 *         if self.stream_is_compressed:             # <<<<<<<<<<<<<<
 *             # Use position as returned by the decompressor.
 *             # The BufferedReader position inside a decompressed stream is meaningless.
 */
  __pyx_t_6 = (__pyx_v_self->stream_is_compressed != 0);
  if (__pyx_t_6) {

    /* "fastwarc/stream_io.pyx":1041
 *             # Use position as returned by the decompressor.
 *             # The BufferedReader position inside a decompressed stream is meaningless.
 *             return self.stream.tell()             # <<<<<<<<<<<<<<
 * 
 *         return self.stream.tell() - self.buf_view.size()
 */
    __pyx_t_5 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->stream->__pyx_vtab)->tell(__pyx_v_self->stream); if (unlikely(__pyx_t_5 == ((size_t)-1L))) __PYX_ERR(1, 1041, __pyx_L1_error)
    __pyx_r = __pyx_t_5;
    goto __pyx_L0;

    /* "fastwarc/stream_io.pyx":1038
 *             return self.limit_consumed
 * 
 *         if self.stream_is_compressed:             # <<<<<<<<<<<<<<
 *             # Use position as returned by the decompressor.
 *             # The BufferedReader position inside a decompressed stream is meaningless.
 */
  }

  /* "fastwarc/stream_io.pyx":1043
 *             return self.stream.tell()
 * 
 *         return self.stream.tell() - self.buf_view.size()             # <<<<<<<<<<<<<<
 * 
 *     cpdef size_t consume(self, size_t size=strnpos) except -1:
 */
  __pyx_t_5 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->stream->__pyx_vtab)->tell(__pyx_v_self->stream); if (unlikely(__pyx_t_5 == ((size_t)-1L))) __PYX_ERR(1, 1043, __pyx_L1_error)
  __pyx_r = (__pyx_t_5 - __pyx_v_self->buf_view.size());
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":1023
 *         return line
 * 
 *     cpdef size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         """
 *         tell(self)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_9tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_14BufferedReader_8tell[] = "\n        tell(self)\n        \n        Offset on the input stream.\n        \n        :return: offset\n        :rtype: int\n        ";
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_9tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("tell (wrapper)", 0);
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_14BufferedReader_8tell(((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_8tell(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  size_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("tell", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_8fastwarc_9stream_io_14BufferedReader_tell(__pyx_v_self, 1); if (unlikely(__pyx_t_1 == ((size_t)-1L))) __PYX_ERR(1, 1023, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1023, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":1045
 *         return self.stream.tell() - self.buf_view.size()
 * 
 *     cpdef size_t consume(self, size_t size=strnpos) except -1:             # <<<<<<<<<<<<<<
 *         """
 *         consume(self, size=-1)
 */

static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_11consume(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static size_t __pyx_f_8fastwarc_9stream_io_14BufferedReader_consume(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_consume *__pyx_optional_args) {
  size_t __pyx_v_size = __pyx_k__5;
  std::string_view *__pyx_v_buf;
  size_t __pyx_v_consumed;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  size_t __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("consume", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_size = __pyx_optional_args->size;
    }
  }
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_consume); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1045, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_11consume)) {
        __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1045, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
          }
        }
        __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1045, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_6 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_6 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 1045, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_6;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "fastwarc/stream_io.pyx":1057
 *         """
 *         cdef string_view* buf
 *         cdef size_t consumed = 0             # <<<<<<<<<<<<<<
 * 
 *         while size > consumed and self._fill_buf():
 */
  __pyx_v_consumed = 0;

  /* "fastwarc/stream_io.pyx":1059
 *         cdef size_t consumed = 0
 * 
 *         while size > consumed and self._fill_buf():             # <<<<<<<<<<<<<<
 *             buf = self._get_buf()
 *             if buf.empty():
 */
  while (1) {
    __pyx_t_8 = ((__pyx_v_size > __pyx_v_consumed) != 0);
    if (__pyx_t_8) {
    } else {
      __pyx_t_7 = __pyx_t_8;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_t_8 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self->__pyx_vtab)->_fill_buf(__pyx_v_self); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(1, 1059, __pyx_L1_error)
    __pyx_t_9 = (__pyx_t_8 != 0);
    __pyx_t_7 = __pyx_t_9;
    __pyx_L5_bool_binop_done:;
    if (!__pyx_t_7) break;

    /* "fastwarc/stream_io.pyx":1060
 * 
 *         while size > consumed and self._fill_buf():
 *             buf = self._get_buf()             # <<<<<<<<<<<<<<
 *             if buf.empty():
 *                 break
 */
    __pyx_v_buf = __pyx_f_8fastwarc_9stream_io_14BufferedReader__get_buf(__pyx_v_self);

    /* "fastwarc/stream_io.pyx":1061
 *         while size > consumed and self._fill_buf():
 *             buf = self._get_buf()
 *             if buf.empty():             # <<<<<<<<<<<<<<
 *                 break
 * 
 */
    __pyx_t_7 = (__pyx_v_buf->empty() != 0);
    if (__pyx_t_7) {

      /* "fastwarc/stream_io.pyx":1062
 *             buf = self._get_buf()
 *             if buf.empty():
 *                 break             # <<<<<<<<<<<<<<
 * 
 *             if size != strnpos:
 */
      goto __pyx_L4_break;

      /* "fastwarc/stream_io.pyx":1061
 *         while size > consumed and self._fill_buf():
 *             buf = self._get_buf()
 *             if buf.empty():             # <<<<<<<<<<<<<<
 *                 break
 * 
 */
    }

    /* "fastwarc/stream_io.pyx":1064
 *                 break
 * 
 *             if size != strnpos:             # <<<<<<<<<<<<<<
 *                 consumed += self._consume_buf(size - consumed)
 *             else:
 */
    __pyx_t_7 = ((__pyx_v_size != std::string::npos) != 0);
    if (__pyx_t_7) {

      /* "fastwarc/stream_io.pyx":1065
 * 
 *             if size != strnpos:
 *                 consumed += self._consume_buf(size - consumed)             # <<<<<<<<<<<<<<
 *             else:
 *                 consumed += self._consume_buf(buf.size())
 */
      __pyx_v_consumed = (__pyx_v_consumed + __pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf(__pyx_v_self, (__pyx_v_size - __pyx_v_consumed)));

      /* "fastwarc/stream_io.pyx":1064
 *                 break
 * 
 *             if size != strnpos:             # <<<<<<<<<<<<<<
 *                 consumed += self._consume_buf(size - consumed)
 *             else:
 */
      goto __pyx_L8;
    }

    /* "fastwarc/stream_io.pyx":1067
 *                 consumed += self._consume_buf(size - consumed)
 *             else:
 *                 consumed += self._consume_buf(buf.size())             # <<<<<<<<<<<<<<
 * 
 *         return consumed
 */
    /*else*/ {
      __pyx_v_consumed = (__pyx_v_consumed + __pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf(__pyx_v_self, __pyx_v_buf->size()));
    }
    __pyx_L8:;
  }
  __pyx_L4_break:;

  /* "fastwarc/stream_io.pyx":1069
 *                 consumed += self._consume_buf(buf.size())
 * 
 *         return consumed             # <<<<<<<<<<<<<<
 * 
 *     cpdef void close(self) except *:
 */
  __pyx_r = __pyx_v_consumed;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pyx":1045
 *         return self.stream.tell() - self.buf_view.size()
 * 
 *     cpdef size_t consume(self, size_t size=strnpos) except -1:             # <<<<<<<<<<<<<<
 *         """
 *         consume(self, size=-1)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.consume", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_11consume(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_14BufferedReader_10consume[] = "\n        consume(self, size=-1)\n        \n        Consume up to ``size`` bytes from the input stream without allocating a buffer for it.\n        \n        :param size: number of bytes to read (default means read remaining stream)\n        :type size: int\n        :return: number of bytes consumed\n        :rtype: int\n        ";
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_11consume(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  size_t __pyx_v_size;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("consume (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_size,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_size);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "consume") < 0)) __PYX_ERR(1, 1045, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    if (values[0]) {
      __pyx_v_size = __Pyx_PyInt_As_size_t(values[0]); if (unlikely((__pyx_v_size == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 1045, __pyx_L3_error)
    } else {
      __pyx_v_size = __pyx_k__5;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("consume", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1045, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.consume", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_14BufferedReader_10consume(((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self), __pyx_v_size);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_10consume(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, size_t __pyx_v_size) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  size_t __pyx_t_1;
  struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_consume __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("consume", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.size = __pyx_v_size;
  __pyx_t_1 = __pyx_vtabptr_8fastwarc_9stream_io_BufferedReader->consume(__pyx_v_self, 1, &__pyx_t_2); if (unlikely(__pyx_t_1 == ((size_t)-1L))) __PYX_ERR(1, 1045, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1045, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.consume", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":1071
 *         return consumed
 * 
 *     cpdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         """
 *         close(self)
 */

static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_13close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static void __pyx_f_8fastwarc_9stream_io_14BufferedReader_close(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self, int __pyx_skip_dispatch) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("close", 0);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1071, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_13close)) {
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1071, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "fastwarc/stream_io.pyx":1077
 *         Close stream.
 *         """
 *         if self.stream is not None:             # <<<<<<<<<<<<<<
 *             self.stream.close()
 * 
 */
  __pyx_t_5 = (((PyObject *)__pyx_v_self->stream) != Py_None);
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "fastwarc/stream_io.pyx":1078
 *         """
 *         if self.stream is not None:
 *             self.stream.close()             # <<<<<<<<<<<<<<
 * 
 * 
 */
    ((struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream *)__pyx_v_self->stream->__pyx_vtab)->close(__pyx_v_self->stream); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 1078, __pyx_L1_error)

    /* "fastwarc/stream_io.pyx":1077
 *         Close stream.
 *         """
 *         if self.stream is not None:             # <<<<<<<<<<<<<<
 *             self.stream.close()
 * 
 */
  }

  /* "fastwarc/stream_io.pyx":1071
 *         return consumed
 * 
 *     cpdef void close(self) except *:             # <<<<<<<<<<<<<<
 *         """
 *         close(self)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_13close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_14BufferedReader_12close[] = "\n        close(self)\n        \n        Close stream.\n        ";
static PyObject *__pyx_pw_8fastwarc_9stream_io_14BufferedReader_13close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_14BufferedReader_12close(((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_14BufferedReader_12close(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("close", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_f_8fastwarc_9stream_io_14BufferedReader_close(__pyx_v_self, 1); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 1071, __pyx_L1_error)
  __pyx_t_1 = __Pyx_void_to_None(NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1071, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("fastwarc.stream_io.BufferedReader.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":1081
 * 
 * 
 * def _buf_reader_py_test_detect_stream_type(BufferedReader buf):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_detect_stream_type(buf):
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_15_buf_reader_py_test_detect_stream_type(PyObject *__pyx_self, PyObject *__pyx_v_buf); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_14_buf_reader_py_test_detect_stream_type[] = "\n    _buf_reader_py_test_detect_stream_type(buf):\n\n    Test interface for :meth:`BufferedReader.detect_stream_type`\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_15_buf_reader_py_test_detect_stream_type = {"_buf_reader_py_test_detect_stream_type", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_15_buf_reader_py_test_detect_stream_type, METH_O, __pyx_doc_8fastwarc_9stream_io_14_buf_reader_py_test_detect_stream_type};
static PyObject *__pyx_pw_8fastwarc_9stream_io_15_buf_reader_py_test_detect_stream_type(PyObject *__pyx_self, PyObject *__pyx_v_buf) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_buf_reader_py_test_detect_stream_type (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_buf), __pyx_ptype_8fastwarc_9stream_io_BufferedReader, 1, "buf", 0))) __PYX_ERR(1, 1081, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_14_buf_reader_py_test_detect_stream_type(__pyx_self, ((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_buf));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_14_buf_reader_py_test_detect_stream_type(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_buf) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_buf_reader_py_test_detect_stream_type", 0);

  /* "fastwarc/stream_io.pyx":1087
 *     Test interface for :meth:`BufferedReader.detect_stream_type`
 *     """
 *     buf.detect_stream_type()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader *)__pyx_v_buf->__pyx_vtab)->detect_stream_type(__pyx_v_buf); if (unlikely(__pyx_t_1 == ((int)0))) __PYX_ERR(1, 1087, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":1081
 * 
 * 
 * def _buf_reader_py_test_detect_stream_type(BufferedReader buf):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_detect_stream_type(buf):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("fastwarc.stream_io._buf_reader_py_test_detect_stream_type", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":1090
 * 
 * 
 * def _buf_reader_py_test_set_limit(BufferedReader buf, size_t limit):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_detect_set_limit(buf, limit):
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_17_buf_reader_py_test_set_limit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_16_buf_reader_py_test_set_limit[] = "\n    _buf_reader_py_test_detect_set_limit(buf, limit):\n\n    Test interface for :meth:`BufferedReader.set_limit`\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_17_buf_reader_py_test_set_limit = {"_buf_reader_py_test_set_limit", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8fastwarc_9stream_io_17_buf_reader_py_test_set_limit, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8fastwarc_9stream_io_16_buf_reader_py_test_set_limit};
static PyObject *__pyx_pw_8fastwarc_9stream_io_17_buf_reader_py_test_set_limit(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_buf = 0;
  size_t __pyx_v_limit;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_buf_reader_py_test_set_limit (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_buf,&__pyx_n_s_limit,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_buf)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_limit)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_buf_reader_py_test_set_limit", 1, 2, 2, 1); __PYX_ERR(1, 1090, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_buf_reader_py_test_set_limit") < 0)) __PYX_ERR(1, 1090, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_buf = ((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)values[0]);
    __pyx_v_limit = __Pyx_PyInt_As_size_t(values[1]); if (unlikely((__pyx_v_limit == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 1090, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_buf_reader_py_test_set_limit", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1090, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("fastwarc.stream_io._buf_reader_py_test_set_limit", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_buf), __pyx_ptype_8fastwarc_9stream_io_BufferedReader, 1, "buf", 0))) __PYX_ERR(1, 1090, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_16_buf_reader_py_test_set_limit(__pyx_self, __pyx_v_buf, __pyx_v_limit);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_16_buf_reader_py_test_set_limit(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_buf, size_t __pyx_v_limit) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_buf_reader_py_test_set_limit", 0);

  /* "fastwarc/stream_io.pyx":1096
 *     Test interface for :meth:`BufferedReader.set_limit`
 *     """
 *     buf.set_limit(limit)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_f_8fastwarc_9stream_io_14BufferedReader_set_limit(__pyx_v_buf, __pyx_v_limit);

  /* "fastwarc/stream_io.pyx":1090
 * 
 * 
 * def _buf_reader_py_test_set_limit(BufferedReader buf, size_t limit):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_detect_set_limit(buf, limit):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pyx":1099
 * 
 * 
 * def _buf_reader_py_test_reset_limit(BufferedReader buf):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_reset_limit(buf, limit):
 */

/* Python wrapper */
static PyObject *__pyx_pw_8fastwarc_9stream_io_19_buf_reader_py_test_reset_limit(PyObject *__pyx_self, PyObject *__pyx_v_buf); /*proto*/
static char __pyx_doc_8fastwarc_9stream_io_18_buf_reader_py_test_reset_limit[] = "\n    _buf_reader_py_test_reset_limit(buf, limit):\n\n    Test interface for :meth:`BufferedReader.reset_limit`\n    ";
static PyMethodDef __pyx_mdef_8fastwarc_9stream_io_19_buf_reader_py_test_reset_limit = {"_buf_reader_py_test_reset_limit", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_19_buf_reader_py_test_reset_limit, METH_O, __pyx_doc_8fastwarc_9stream_io_18_buf_reader_py_test_reset_limit};
static PyObject *__pyx_pw_8fastwarc_9stream_io_19_buf_reader_py_test_reset_limit(PyObject *__pyx_self, PyObject *__pyx_v_buf) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_buf_reader_py_test_reset_limit (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_buf), __pyx_ptype_8fastwarc_9stream_io_BufferedReader, 1, "buf", 0))) __PYX_ERR(1, 1099, __pyx_L1_error)
  __pyx_r = __pyx_pf_8fastwarc_9stream_io_18_buf_reader_py_test_reset_limit(__pyx_self, ((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)__pyx_v_buf));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8fastwarc_9stream_io_18_buf_reader_py_test_reset_limit(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *__pyx_v_buf) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_buf_reader_py_test_reset_limit", 0);

  /* "fastwarc/stream_io.pyx":1105
 *     Test interface for :meth:`BufferedReader.reset_limit`
 *     """
 *     buf.reset_limit()             # <<<<<<<<<<<<<<
 */
  __pyx_f_8fastwarc_9stream_io_14BufferedReader_reset_limit(__pyx_v_buf);

  /* "fastwarc/stream_io.pyx":1099
 * 
 * 
 * def _buf_reader_py_test_reset_limit(BufferedReader buf):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_reset_limit(buf, limit):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pxd":38
 *     cdef object py_stream
 * 
 *     cdef inline size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         cdef bytes data = self.py_stream.read(size)
 *         size = min(<size_t>len(data), size)
 */

static size_t __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_read(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, char *__pyx_v_out, size_t __pyx_v_size) {
  PyObject *__pyx_v_data = 0;
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  size_t __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  size_t __pyx_t_7;
  size_t __pyx_t_8;
  char *__pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("read", 0);

  /* "fastwarc/stream_io.pxd":39
 * 
 *     cdef inline size_t read(self, char* out, size_t size) except -1:
 *         cdef bytes data = self.py_stream.read(size)             # <<<<<<<<<<<<<<
 *         size = min(<size_t>len(data), size)
 *         memcpy(out, <char*>data, size * sizeof(char))
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->py_stream, __pyx_n_s_read); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 39, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 39, __pyx_L1_error)
  __pyx_v_data = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pxd":40
 *     cdef inline size_t read(self, char* out, size_t size) except -1:
 *         cdef bytes data = self.py_stream.read(size)
 *         size = min(<size_t>len(data), size)             # <<<<<<<<<<<<<<
 *         memcpy(out, <char*>data, size * sizeof(char))
 *         return size
 */
  __pyx_t_5 = __pyx_v_size;
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 40, __pyx_L1_error)
  }
  __pyx_t_6 = PyBytes_GET_SIZE(__pyx_v_data); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 40, __pyx_L1_error)
  __pyx_t_7 = ((size_t)__pyx_t_6);
  if (((__pyx_t_5 < __pyx_t_7) != 0)) {
    __pyx_t_8 = __pyx_t_5;
  } else {
    __pyx_t_8 = __pyx_t_7;
  }
  __pyx_v_size = __pyx_t_8;

  /* "fastwarc/stream_io.pxd":41
 *         cdef bytes data = self.py_stream.read(size)
 *         size = min(<size_t>len(data), size)
 *         memcpy(out, <char*>data, size * sizeof(char))             # <<<<<<<<<<<<<<
 *         return size
 * 
 */
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
    __PYX_ERR(0, 41, __pyx_L1_error)
  }
  __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_data); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 41, __pyx_L1_error)
  (void)(memcpy(__pyx_v_out, ((char *)__pyx_t_9), (__pyx_v_size * (sizeof(char)))));

  /* "fastwarc/stream_io.pxd":42
 *         size = min(<size_t>len(data), size)
 *         memcpy(out, <char*>data, size * sizeof(char))
 *         return size             # <<<<<<<<<<<<<<
 * 
 *     cdef inline size_t write(self, const char* data, size_t size) except -1:
 */
  __pyx_r = __pyx_v_size;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pxd":38
 *     cdef object py_stream
 * 
 *     cdef inline size_t read(self, char* out, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         cdef bytes data = self.py_stream.read(size)
 *         size = min(<size_t>len(data), size)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.PythonIOStreamAdapter.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pxd":44
 *         return size
 * 
 *     cdef inline size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         return self.py_stream.write(data[:size])
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_write(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, char const *__pyx_v_data, size_t __pyx_v_size) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  size_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write", 0);

  /* "fastwarc/stream_io.pxd":45
 * 
 *     cdef inline size_t write(self, const char* data, size_t size) except -1:
 *         return self.py_stream.write(data[:size])             # <<<<<<<<<<<<<<
 * 
 *     cdef inline size_t tell(self) except -1:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->py_stream, __pyx_n_s_write); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_data + 0, __pyx_v_size - 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyInt_As_size_t(__pyx_t_1); if (unlikely((__pyx_t_5 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pxd":44
 *         return size
 * 
 *     cdef inline size_t write(self, const char* data, size_t size) except -1:             # <<<<<<<<<<<<<<
 *         return self.py_stream.write(data[:size])
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.PythonIOStreamAdapter.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pxd":47
 *         return self.py_stream.write(data[:size])
 * 
 *     cdef inline size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         return self.py_stream.tell()
 * 
 */

static size_t __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_tell(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self) {
  size_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  size_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("tell", 0);

  /* "fastwarc/stream_io.pxd":48
 * 
 *     cdef inline size_t tell(self) except -1:
 *         return self.py_stream.tell()             # <<<<<<<<<<<<<<
 * 
 *     cdef inline void seek(self, size_t offset) except *:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->py_stream, __pyx_n_s_tell); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyInt_As_size_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_4;
  goto __pyx_L0;

  /* "fastwarc/stream_io.pxd":47
 *         return self.py_stream.write(data[:size])
 * 
 *     cdef inline size_t tell(self) except -1:             # <<<<<<<<<<<<<<
 *         return self.py_stream.tell()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("fastwarc.stream_io.PythonIOStreamAdapter.tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1L;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "fastwarc/stream_io.pxd":50
 *         return self.py_stream.tell()
 * 
 *     cdef inline void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         self.py_stream.seek(offset)
 * 
 */

static void __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_seek(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self, size_t __pyx_v_offset) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("seek", 0);

  /* "fastwarc/stream_io.pxd":51
 * 
 *     cdef inline void seek(self, size_t offset) except *:
 *         self.py_stream.seek(offset)             # <<<<<<<<<<<<<<
 * 
 *     cdef inline void flush(self) except *:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->py_stream, __pyx_n_s_seek); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pxd":50
 *         return self.py_stream.tell()
 * 
 *     cdef inline void seek(self, size_t offset) except *:             # <<<<<<<<<<<<<<
 *         self.py_stream.seek(offset)
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("fastwarc.stream_io.PythonIOStreamAdapter.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pxd":53
 *         self.py_stream.seek(offset)
 * 
 *     cdef inline void flush(self) except *:             # <<<<<<<<<<<<<<
 *         self.py_stream.flush()
 * 
 */

static void __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_flush(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("flush", 0);

  /* "fastwarc/stream_io.pxd":54
 * 
 *     cdef inline void flush(self) except *:
 *         self.py_stream.flush()             # <<<<<<<<<<<<<<
 * 
 *     cdef inline void close(self) except *:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->py_stream, __pyx_n_s_flush); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pxd":53
 *         self.py_stream.seek(offset)
 * 
 *     cdef inline void flush(self) except *:             # <<<<<<<<<<<<<<
 *         self.py_stream.flush()
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("fastwarc.stream_io.PythonIOStreamAdapter.flush", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "fastwarc/stream_io.pxd":56
 *         self.py_stream.flush()
 * 
 *     cdef inline void close(self) except *:             # <<<<<<<<<<<<<<
 *         if self.py_stream is None:
 *             return
 */

static void __pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_close(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("close", 0);

  /* "fastwarc/stream_io.pxd":57
 * 
 *     cdef inline void close(self) except *:
 *         if self.py_stream is None:             # <<<<<<<<<<<<<<
 *             return
 *         try:
 */
  __pyx_t_1 = (__pyx_v_self->py_stream == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "fastwarc/stream_io.pxd":58
 *     cdef inline void close(self) except *:
 *         if self.py_stream is None:
 *             return             # <<<<<<<<<<<<<<
 *         try:
 *             self.py_stream.close()
 */
    goto __pyx_L0;

    /* "fastwarc/stream_io.pxd":57
 * 
 *     cdef inline void close(self) except *:
 *         if self.py_stream is None:             # <<<<<<<<<<<<<<
 *             return
 *         try:
 */
  }

  /* "fastwarc/stream_io.pxd":59
 *         if self.py_stream is None:
 *             return
 *         try:             # <<<<<<<<<<<<<<
 *             self.py_stream.close()
 *         except ValueError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_5);
    /*try:*/ {

      /* "fastwarc/stream_io.pxd":60
 *             return
 *         try:
 *             self.py_stream.close()             # <<<<<<<<<<<<<<
 *         except ValueError:
 *             # Ignore if already closed
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->py_stream, __pyx_n_s_close); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 60, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 60, __pyx_L4_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "fastwarc/stream_io.pxd":59
 *         if self.py_stream is None:
 *             return
 *         try:             # <<<<<<<<<<<<<<
 *             self.py_stream.close()
 *         except ValueError:
 */
    }
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L9_try_end;
    __pyx_L4_error:;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "fastwarc/stream_io.pxd":61
 *         try:
 *             self.py_stream.close()
 *         except ValueError:             # <<<<<<<<<<<<<<
 *             # Ignore if already closed
 *             pass
 */
    __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_9) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L5_exception_handled;
    }
    goto __pyx_L6_except_error;
    __pyx_L6_except_error:;

    /* "fastwarc/stream_io.pxd":59
 *         if self.py_stream is None:
 *             return
 *         try:             # <<<<<<<<<<<<<<
 *             self.py_stream.close()
 *         except ValueError:
 */
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
    goto __pyx_L1_error;
    __pyx_L5_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
    __pyx_L9_try_end:;
  }

  /* "fastwarc/stream_io.pxd":56
 *         self.py_stream.flush()
 * 
 *     cdef inline void close(self) except *:             # <<<<<<<<<<<<<<
 *         if self.py_stream is None:
 *             return
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("fastwarc.stream_io.PythonIOStreamAdapter.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "string.from_py":13
 * 
 * @cname("__pyx_convert_string_from_py_std__in_string")
 * cdef string __pyx_convert_string_from_py_std__in_string(object o) except *:             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t length = 0
 *     cdef const char* data = __Pyx_PyObject_AsStringAndSize(o, &length)
 */

static std::string __pyx_convert_string_from_py_std__in_string(PyObject *__pyx_v_o) {
  Py_ssize_t __pyx_v_length;
  char const *__pyx_v_data;
  std::string __pyx_r;
  __Pyx_RefNannyDeclarations
  char const *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_string_from_py_std__in_string", 0);

  /* "string.from_py":14
 * @cname("__pyx_convert_string_from_py_std__in_string")
 * cdef string __pyx_convert_string_from_py_std__in_string(object o) except *:
 *     cdef Py_ssize_t length = 0             # <<<<<<<<<<<<<<
 *     cdef const char* data = __Pyx_PyObject_AsStringAndSize(o, &length)
 *     return string(data, length)
 */
  __pyx_v_length = 0;

  /* "string.from_py":15
 * cdef string __pyx_convert_string_from_py_std__in_string(object o) except *:
 *     cdef Py_ssize_t length = 0
 *     cdef const char* data = __Pyx_PyObject_AsStringAndSize(o, &length)             # <<<<<<<<<<<<<<
 *     return string(data, length)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_AsStringAndSize(__pyx_v_o, (&__pyx_v_length)); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(2, 15, __pyx_L1_error)
  __pyx_v_data = __pyx_t_1;

  /* "string.from_py":16
 *     cdef Py_ssize_t length = 0
 *     cdef const char* data = __Pyx_PyObject_AsStringAndSize(o, &length)
 *     return string(data, length)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = std::string(__pyx_v_data, __pyx_v_length);
  goto __pyx_L0;

  /* "string.from_py":13
 * 
 * @cname("__pyx_convert_string_from_py_std__in_string")
 * cdef string __pyx_convert_string_from_py_std__in_string(object o) except *:             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t length = 0
 *     cdef const char* data = __Pyx_PyObject_AsStringAndSize(o, &length)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("string.from_py.__pyx_convert_string_from_py_std__in_string", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_pretend_to_initialize(&__pyx_r);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "string.to_py":31
 * 
 * @cname("__pyx_convert_PyObject_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyObject_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyObject_FromStringAndSize(s.data(), s.size())
 * cdef extern from *:
 */

static CYTHON_INLINE PyObject *__pyx_convert_PyObject_string_to_py_std__in_string(std::string const &__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_PyObject_string_to_py_std__in_string", 0);

  /* "string.to_py":32
 * @cname("__pyx_convert_PyObject_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyObject_string_to_py_std__in_string(const string& s):
 *     return __Pyx_PyObject_FromStringAndSize(s.data(), s.size())             # <<<<<<<<<<<<<<
 * cdef extern from *:
 *     cdef object __Pyx_PyUnicode_FromStringAndSize(const char*, size_t)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_FromStringAndSize(__pyx_v_s.data(), __pyx_v_s.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "string.to_py":31
 * 
 * @cname("__pyx_convert_PyObject_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyObject_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyObject_FromStringAndSize(s.data(), s.size())
 * cdef extern from *:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("string.to_py.__pyx_convert_PyObject_string_to_py_std__in_string", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "string.to_py":37
 * 
 * @cname("__pyx_convert_PyUnicode_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyUnicode_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyUnicode_FromStringAndSize(s.data(), s.size())
 * cdef extern from *:
 */

static CYTHON_INLINE PyObject *__pyx_convert_PyUnicode_string_to_py_std__in_string(std::string const &__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_PyUnicode_string_to_py_std__in_string", 0);

  /* "string.to_py":38
 * @cname("__pyx_convert_PyUnicode_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyUnicode_string_to_py_std__in_string(const string& s):
 *     return __Pyx_PyUnicode_FromStringAndSize(s.data(), s.size())             # <<<<<<<<<<<<<<
 * cdef extern from *:
 *     cdef object __Pyx_PyStr_FromStringAndSize(const char*, size_t)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyUnicode_FromStringAndSize(__pyx_v_s.data(), __pyx_v_s.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "string.to_py":37
 * 
 * @cname("__pyx_convert_PyUnicode_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyUnicode_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyUnicode_FromStringAndSize(s.data(), s.size())
 * cdef extern from *:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("string.to_py.__pyx_convert_PyUnicode_string_to_py_std__in_string", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "string.to_py":43
 * 
 * @cname("__pyx_convert_PyStr_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyStr_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyStr_FromStringAndSize(s.data(), s.size())
 * cdef extern from *:
 */

static CYTHON_INLINE PyObject *__pyx_convert_PyStr_string_to_py_std__in_string(std::string const &__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_PyStr_string_to_py_std__in_string", 0);

  /* "string.to_py":44
 * @cname("__pyx_convert_PyStr_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyStr_string_to_py_std__in_string(const string& s):
 *     return __Pyx_PyStr_FromStringAndSize(s.data(), s.size())             # <<<<<<<<<<<<<<
 * cdef extern from *:
 *     cdef object __Pyx_PyBytes_FromStringAndSize(const char*, size_t)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyStr_FromStringAndSize(__pyx_v_s.data(), __pyx_v_s.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "string.to_py":43
 * 
 * @cname("__pyx_convert_PyStr_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyStr_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyStr_FromStringAndSize(s.data(), s.size())
 * cdef extern from *:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("string.to_py.__pyx_convert_PyStr_string_to_py_std__in_string", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "string.to_py":49
 * 
 * @cname("__pyx_convert_PyBytes_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyBytes_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyBytes_FromStringAndSize(s.data(), s.size())
 * cdef extern from *:
 */

static CYTHON_INLINE PyObject *__pyx_convert_PyBytes_string_to_py_std__in_string(std::string const &__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_PyBytes_string_to_py_std__in_string", 0);

  /* "string.to_py":50
 * @cname("__pyx_convert_PyBytes_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyBytes_string_to_py_std__in_string(const string& s):
 *     return __Pyx_PyBytes_FromStringAndSize(s.data(), s.size())             # <<<<<<<<<<<<<<
 * cdef extern from *:
 *     cdef object __Pyx_PyByteArray_FromStringAndSize(const char*, size_t)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s.data(), __pyx_v_s.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "string.to_py":49
 * 
 * @cname("__pyx_convert_PyBytes_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyBytes_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyBytes_FromStringAndSize(s.data(), s.size())
 * cdef extern from *:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("string.to_py.__pyx_convert_PyBytes_string_to_py_std__in_string", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "string.to_py":55
 * 
 * @cname("__pyx_convert_PyByteArray_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyByteArray_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyByteArray_FromStringAndSize(s.data(), s.size())
 * 
 */

static CYTHON_INLINE PyObject *__pyx_convert_PyByteArray_string_to_py_std__in_string(std::string const &__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_PyByteArray_string_to_py_std__in_string", 0);

  /* "string.to_py":56
 * @cname("__pyx_convert_PyByteArray_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyByteArray_string_to_py_std__in_string(const string& s):
 *     return __Pyx_PyByteArray_FromStringAndSize(s.data(), s.size())             # <<<<<<<<<<<<<<
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyByteArray_FromStringAndSize(__pyx_v_s.data(), __pyx_v_s.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 56, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "string.to_py":55
 * 
 * @cname("__pyx_convert_PyByteArray_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyByteArray_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyByteArray_FromStringAndSize(s.data(), s.size())
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("string.to_py.__pyx_convert_PyByteArray_string_to_py_std__in_string", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream __pyx_vtable_8fastwarc_9stream_io_IOStream;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_IOStream(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_IOStream *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)o);
  p->__pyx_vtab = __pyx_vtabptr_8fastwarc_9stream_io_IOStream;
  return o;
}

static void __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyMethodDef __pyx_methods_8fastwarc_9stream_io_IOStream[] = {
  {"__enter__", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_8IOStream_1__enter__, METH_NOARGS, __pyx_doc_8fastwarc_9stream_io_8IOStream___enter__},
  {"__exit__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8fastwarc_9stream_io_8IOStream_3__exit__, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_8fastwarc_9stream_io_IOStream = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.IOStream", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_IOStream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "IOStream base class.", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_8fastwarc_9stream_io_IOStream, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_IOStream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_PythonIOStreamAdapter __pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_PythonIOStreamAdapter(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *p;
  PyObject *o = __pyx_tp_new_8fastwarc_9stream_io_IOStream(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream*)__pyx_vtabptr_8fastwarc_9stream_io_PythonIOStreamAdapter;
  p->py_stream = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_8fastwarc_9stream_io_21PythonIOStreamAdapter_3__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_8fastwarc_9stream_io_PythonIOStreamAdapter(PyObject *o) {
  struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *p = (struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->py_stream);
  #if CYTHON_USE_TYPE_SLOTS
  if (PyType_IS_GC(Py_TYPE(o)->tp_base))
  #endif
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream(o);
}

static int __pyx_tp_traverse_8fastwarc_9stream_io_PythonIOStreamAdapter(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *p = (struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *)o;
  e = ((likely(__pyx_ptype_8fastwarc_9stream_io_IOStream)) ? ((__pyx_ptype_8fastwarc_9stream_io_IOStream->tp_traverse) ? __pyx_ptype_8fastwarc_9stream_io_IOStream->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_8fastwarc_9stream_io_PythonIOStreamAdapter)); if (e) return e;
  if (p->py_stream) {
    e = (*v)(p->py_stream, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_8fastwarc_9stream_io_PythonIOStreamAdapter(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *p = (struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter *)o;
  if (likely(__pyx_ptype_8fastwarc_9stream_io_IOStream)) { if (__pyx_ptype_8fastwarc_9stream_io_IOStream->tp_clear) __pyx_ptype_8fastwarc_9stream_io_IOStream->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_8fastwarc_9stream_io_PythonIOStreamAdapter);
  tmp = ((PyObject*)p->py_stream);
  p->py_stream = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_8fastwarc_9stream_io_PythonIOStreamAdapter[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.PythonIOStreamAdapter", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_PythonIOStreamAdapter), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_PythonIOStreamAdapter, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "\n    __init__(self, py_stream)\n\n    IOStream adapter for file-like Python objects.\n\n    :param py_stream: input Python stream object\n    ", /*tp_doc*/
  __pyx_tp_traverse_8fastwarc_9stream_io_PythonIOStreamAdapter, /*tp_traverse*/
  __pyx_tp_clear_8fastwarc_9stream_io_PythonIOStreamAdapter, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_8fastwarc_9stream_io_PythonIOStreamAdapter, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_8fastwarc_9stream_io_21PythonIOStreamAdapter_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_PythonIOStreamAdapter, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_BytesIOStream __pyx_vtable_8fastwarc_9stream_io_BytesIOStream;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_BytesIOStream(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *p;
  PyObject *o = __pyx_tp_new_8fastwarc_9stream_io_IOStream(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream*)__pyx_vtabptr_8fastwarc_9stream_io_BytesIOStream;
  new((void*)&(p->buffer)) std::string();
  if (unlikely(__pyx_pw_8fastwarc_9stream_io_13BytesIOStream_3__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_8fastwarc_9stream_io_BytesIOStream(PyObject *o) {
  struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *p = (struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  __Pyx_call_destructor(p->buffer);
  __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream(o);
}

static PyMethodDef __pyx_methods_8fastwarc_9stream_io_BytesIOStream[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_8fastwarc_9stream_io_BytesIOStream = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.BytesIOStream", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_BytesIOStream, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "\n    __init__(self, initial_data=None)\n\n    IOStream that uses an in-memory buffer.\n\n    :param initial_data: fill internal buffer with this initial data\n    :type initial_data: bytes\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_8fastwarc_9stream_io_BytesIOStream, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_8fastwarc_9stream_io_13BytesIOStream_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_BytesIOStream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_FileStream __pyx_vtable_8fastwarc_9stream_io_FileStream;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_FileStream(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_FileStream *p;
  PyObject *o = __pyx_tp_new_8fastwarc_9stream_io_IOStream(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_FileStream *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream*)__pyx_vtabptr_8fastwarc_9stream_io_FileStream;
  if (unlikely(__pyx_pw_8fastwarc_9stream_io_10FileStream_3__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_8fastwarc_9stream_io_FileStream(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_8fastwarc_9stream_io_10FileStream_5__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream(o);
}

static PyMethodDef __pyx_methods_8fastwarc_9stream_io_FileStream[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_8fastwarc_9stream_io_FileStream = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.FileStream", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_FileStream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_FileStream, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "\n    __init__(self, filename=None, mode='rb')\n\n    Fast alternative to Python file objects for local files.\n\n    :param filename: input filename\n    :type filename: str\n    :param mode: file open mode\n    :type mode: str\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_8fastwarc_9stream_io_FileStream, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_8fastwarc_9stream_io_10FileStream_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_FileStream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_CompressingStream __pyx_vtable_8fastwarc_9stream_io_CompressingStream;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_CompressingStream(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *p;
  PyObject *o = __pyx_tp_new_8fastwarc_9stream_io_IOStream(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream*)__pyx_vtabptr_8fastwarc_9stream_io_CompressingStream;
  return o;
}

static PyTypeObject __pyx_type_8fastwarc_9stream_io_CompressingStream = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.CompressingStream", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "Base class for compressed :class:`IOStream` types.", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_CompressingStream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_GZipStream __pyx_vtable_8fastwarc_9stream_io_GZipStream;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_GZipStream(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_GZipStream *p;
  PyObject *o = __pyx_tp_new_8fastwarc_9stream_io_CompressingStream(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)o);
  p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream*)__pyx_vtabptr_8fastwarc_9stream_io_GZipStream;
  new((void*)&(p->working_buf)) std::string();
  p->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_8fastwarc_9stream_io_10GZipStream_3__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_8fastwarc_9stream_io_GZipStream(PyObject *o) {
  struct __pyx_obj_8fastwarc_9stream_io_GZipStream *p = (struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_8fastwarc_9stream_io_10GZipStream_5__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  __Pyx_call_destructor(p->working_buf);
  Py_CLEAR(p->raw_stream);
  #if CYTHON_USE_TYPE_SLOTS
  if (PyType_IS_GC(Py_TYPE(o)->tp_base))
  #endif
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream(o);
}

static int __pyx_tp_traverse_8fastwarc_9stream_io_GZipStream(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_8fastwarc_9stream_io_GZipStream *p = (struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)o;
  e = ((likely(__pyx_ptype_8fastwarc_9stream_io_CompressingStream)) ? ((__pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_traverse) ? __pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_8fastwarc_9stream_io_GZipStream)); if (e) return e;
  if (p->raw_stream) {
    e = (*v)(((PyObject *)p->raw_stream), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_8fastwarc_9stream_io_GZipStream(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_8fastwarc_9stream_io_GZipStream *p = (struct __pyx_obj_8fastwarc_9stream_io_GZipStream *)o;
  if (likely(__pyx_ptype_8fastwarc_9stream_io_CompressingStream)) { if (__pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_clear) __pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_8fastwarc_9stream_io_GZipStream);
  tmp = ((PyObject*)p->raw_stream);
  p->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_8fastwarc_9stream_io_GZipStream[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_8fastwarc_9stream_io_GZipStream = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.GZipStream", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_GZipStream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_GZipStream, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "\n    __init__(self, raw_stream, compression_level=9, zlib=False)\n\n    GZip :class:`IOStream` implementation.\n\n    :param raw_stream: raw data stream\n    :param compression_level: GZip compression level (for compression only)\n    :type compression_level: int\n    :param zlib: use raw deflate / zlib format instead of gzip\n    :type zlib: bool\n    ", /*tp_doc*/
  __pyx_tp_traverse_8fastwarc_9stream_io_GZipStream, /*tp_traverse*/
  __pyx_tp_clear_8fastwarc_9stream_io_GZipStream, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_8fastwarc_9stream_io_GZipStream, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_8fastwarc_9stream_io_10GZipStream_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_GZipStream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_LZ4Stream __pyx_vtable_8fastwarc_9stream_io_LZ4Stream;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_LZ4Stream(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *p;
  PyObject *o = __pyx_tp_new_8fastwarc_9stream_io_CompressingStream(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)o);
  p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream*)__pyx_vtabptr_8fastwarc_9stream_io_LZ4Stream;
  new((void*)&(p->working_buf)) std::string();
  p->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_8fastwarc_9stream_io_9LZ4Stream_3__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_8fastwarc_9stream_io_LZ4Stream(PyObject *o) {
  struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *p = (struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_8fastwarc_9stream_io_9LZ4Stream_5__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  __Pyx_call_destructor(p->working_buf);
  Py_CLEAR(p->raw_stream);
  #if CYTHON_USE_TYPE_SLOTS
  if (PyType_IS_GC(Py_TYPE(o)->tp_base))
  #endif
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream(o);
}

static int __pyx_tp_traverse_8fastwarc_9stream_io_LZ4Stream(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *p = (struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)o;
  e = ((likely(__pyx_ptype_8fastwarc_9stream_io_CompressingStream)) ? ((__pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_traverse) ? __pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_8fastwarc_9stream_io_LZ4Stream)); if (e) return e;
  if (p->raw_stream) {
    e = (*v)(((PyObject *)p->raw_stream), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_8fastwarc_9stream_io_LZ4Stream(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *p = (struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *)o;
  if (likely(__pyx_ptype_8fastwarc_9stream_io_CompressingStream)) { if (__pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_clear) __pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_8fastwarc_9stream_io_LZ4Stream);
  tmp = ((PyObject*)p->raw_stream);
  p->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_8fastwarc_9stream_io_LZ4Stream[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_8fastwarc_9stream_io_LZ4Stream = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.LZ4Stream", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_LZ4Stream, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "\n    __init__(self, raw_stream, compression_level=12, favor_dec_speed=True)\n\n    LZ4 :class:`IOStream` implementation.\n\n    :param raw_stream: raw data stream\n    :param compression_level: LZ4 compression level (for compression only)\n    :type compression_level: int\n    :param favor_dec_speed: favour decompression speed over compression speed and size\n    :type favor_dec_speed: bool\n    ", /*tp_doc*/
  __pyx_tp_traverse_8fastwarc_9stream_io_LZ4Stream, /*tp_traverse*/
  __pyx_tp_clear_8fastwarc_9stream_io_LZ4Stream, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_8fastwarc_9stream_io_LZ4Stream, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_8fastwarc_9stream_io_9LZ4Stream_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_LZ4Stream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_BrotliStream __pyx_vtable_8fastwarc_9stream_io_BrotliStream;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_BrotliStream(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *p;
  PyObject *o = __pyx_tp_new_8fastwarc_9stream_io_CompressingStream(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *)o);
  p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_8fastwarc_9stream_io_IOStream*)__pyx_vtabptr_8fastwarc_9stream_io_BrotliStream;
  new((void*)&(p->working_buf)) std::string();
  p->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)Py_None); Py_INCREF(Py_None);
  p->compressor = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_8fastwarc_9stream_io_12BrotliStream_3__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_8fastwarc_9stream_io_BrotliStream(PyObject *o) {
  struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *p = (struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  __Pyx_call_destructor(p->working_buf);
  Py_CLEAR(p->raw_stream);
  Py_CLEAR(p->compressor);
  #if CYTHON_USE_TYPE_SLOTS
  if (PyType_IS_GC(Py_TYPE(o)->tp_base))
  #endif
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_8fastwarc_9stream_io_IOStream(o);
}

static int __pyx_tp_traverse_8fastwarc_9stream_io_BrotliStream(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *p = (struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *)o;
  e = ((likely(__pyx_ptype_8fastwarc_9stream_io_CompressingStream)) ? ((__pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_traverse) ? __pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_8fastwarc_9stream_io_BrotliStream)); if (e) return e;
  if (p->raw_stream) {
    e = (*v)(((PyObject *)p->raw_stream), a); if (e) return e;
  }
  if (p->compressor) {
    e = (*v)(p->compressor, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_8fastwarc_9stream_io_BrotliStream(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *p = (struct __pyx_obj_8fastwarc_9stream_io_BrotliStream *)o;
  if (likely(__pyx_ptype_8fastwarc_9stream_io_CompressingStream)) { if (__pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_clear) __pyx_ptype_8fastwarc_9stream_io_CompressingStream->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_8fastwarc_9stream_io_BrotliStream);
  tmp = ((PyObject*)p->raw_stream);
  p->raw_stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->compressor);
  p->compressor = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_8fastwarc_9stream_io_BrotliStream[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_8fastwarc_9stream_io_BrotliStream = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.BrotliStream", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_BrotliStream), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_BrotliStream, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "\n    __init__(self, raw_stream, quality=11, lgwin=22, lgblock=0)\n\n    Brotli :class:`IOStream` implementation.\n\n    Implementation relies on Google's ``brotli`` Python package, will be ported to native\n    C version in a later version.\n\n    :param raw_stream: raw data stream\n    :param quality: compression quality (higher quality means better compression, but less speed)\n    :type quality: int\n    :param lgwin: Base 2 logarithm of the sliding window size in the range 16 to 24\n    :type lgwin: int\n    :param lgblock: Base 2 logarithm of the maximum input block size in the range 16 to 24\n                    (will be set based on quality of value is 0)\n    :type lgblock: int\n    ", /*tp_doc*/
  __pyx_tp_traverse_8fastwarc_9stream_io_BrotliStream, /*tp_traverse*/
  __pyx_tp_clear_8fastwarc_9stream_io_BrotliStream, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_8fastwarc_9stream_io_BrotliStream, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_8fastwarc_9stream_io_12BrotliStream_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_BrotliStream, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_8fastwarc_9stream_io_BufferedReader __pyx_vtable_8fastwarc_9stream_io_BufferedReader;

static PyObject *__pyx_tp_new_8fastwarc_9stream_io_BufferedReader(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)o);
  p->__pyx_vtab = __pyx_vtabptr_8fastwarc_9stream_io_BufferedReader;
  new((void*)&(p->errstr)) std::string();
  new((void*)&(p->buf)) std::string();
  new((void*)&(p->buf_view)) std::string_view();
  new((void*)&(p->limited_buf_view)) std::string_view();
  p->stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_8fastwarc_9stream_io_14BufferedReader_3__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_8fastwarc_9stream_io_BufferedReader(PyObject *o) {
  struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *p = (struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  __Pyx_call_destructor(p->errstr);
  __Pyx_call_destructor(p->buf);
  __Pyx_call_destructor(p->buf_view);
  __Pyx_call_destructor(p->limited_buf_view);
  Py_CLEAR(p->stream);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_8fastwarc_9stream_io_BufferedReader(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *p = (struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)o;
  if (p->stream) {
    e = (*v)(((PyObject *)p->stream), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_8fastwarc_9stream_io_BufferedReader(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *p = (struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *)o;
  tmp = ((PyObject*)p->stream);
  p->stream = ((struct __pyx_obj_8fastwarc_9stream_io_IOStream *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_8fastwarc_9stream_io_BufferedReader[] = {
  {"read", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_5read, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8fastwarc_9stream_io_14BufferedReader_4read},
  {"readline", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_7readline, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8fastwarc_9stream_io_14BufferedReader_6readline},
  {"tell", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_9tell, METH_NOARGS, __pyx_doc_8fastwarc_9stream_io_14BufferedReader_8tell},
  {"consume", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_11consume, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8fastwarc_9stream_io_14BufferedReader_10consume},
  {"close", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_14BufferedReader_13close, METH_NOARGS, __pyx_doc_8fastwarc_9stream_io_14BufferedReader_12close},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_8fastwarc_9stream_io_BufferedReader = {
  PyVarObject_HEAD_INIT(0, 0)
  "fastwarc.stream_io.BufferedReader", /*tp_name*/
  sizeof(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_8fastwarc_9stream_io_BufferedReader, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "\n    __init__(self, stream, buf_size=16384, negotiate_stream=True)\n\n    Buffered reader operating on an :class:`IOStream` instance.\n\n    :param stream: stream to operate on\n    :type stream: IOStream\n    :param buf_size: internal buffer size\n    :type buf_size: int\n    :param negotiate_stream: whether to auto-negotiate stream type\n    :type negotiate_stream: bool\n    ", /*tp_doc*/
  __pyx_tp_traverse_8fastwarc_9stream_io_BufferedReader, /*tp_traverse*/
  __pyx_tp_clear_8fastwarc_9stream_io_BufferedReader, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_8fastwarc_9stream_io_BufferedReader, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_8fastwarc_9stream_io_14BufferedReader_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_8fastwarc_9stream_io_BufferedReader, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {"wrap_stream", (PyCFunction)__pyx_pw_8fastwarc_9stream_io_13wrap_stream, METH_O, __pyx_doc_8fastwarc_9stream_io_12wrap_stream},
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec_stream_io(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec_stream_io},
  {0, NULL}
};
#endif

static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "stream_io",
    0, /* m_doc */
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    0, /* m_size */
  #else
    -1, /* m_size */
  #endif
    __pyx_methods /* m_methods */,
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    __pyx_moduledef_slots, /* m_slots */
  #else
    NULL, /* m_reload */
  #endif
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
    #define CYTHON_SMALL_CODE __attribute__((cold))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_s_BrotliStream, __pyx_k_BrotliStream, sizeof(__pyx_k_BrotliStream), 0, 0, 1, 1},
  {&__pyx_n_s_BufferedReader, __pyx_k_BufferedReader, sizeof(__pyx_k_BufferedReader), 0, 0, 1, 1},
  {&__pyx_n_s_BytesIOStream, __pyx_k_BytesIOStream, sizeof(__pyx_k_BytesIOStream), 0, 0, 1, 1},
  {&__pyx_n_s_CompressingStream, __pyx_k_CompressingStream, sizeof(__pyx_k_CompressingStream), 0, 0, 1, 1},
  {&__pyx_kp_u_Compression_in_progress, __pyx_k_Compression_in_progress, sizeof(__pyx_k_Compression_in_progress), 0, 1, 0, 0},
  {&__pyx_n_s_Compressor, __pyx_k_Compressor, sizeof(__pyx_k_Compressor), 0, 0, 1, 1},
  {&__pyx_kp_u_Decompression_in_progress, __pyx_k_Decompression_in_progress, sizeof(__pyx_k_Decompression_in_progress), 0, 1, 0, 0},
  {&__pyx_kp_u_Decompression_in_progress_2, __pyx_k_Decompression_in_progress_2, sizeof(__pyx_k_Decompression_in_progress_2), 0, 1, 0, 0},
  {&__pyx_n_s_Decompressor, __pyx_k_Decompressor, sizeof(__pyx_k_Decompressor), 0, 0, 1, 1},
  {&__pyx_kp_u_Error_reading_file, __pyx_k_Error_reading_file, sizeof(__pyx_k_Error_reading_file), 0, 1, 0, 0},
  {&__pyx_kp_u_Error_writing_file, __pyx_k_Error_writing_file, sizeof(__pyx_k_Error_writing_file), 0, 1, 0, 0},
  {&__pyx_kp_u_Failed_to_create_compression_con, __pyx_k_Failed_to_create_compression_con, sizeof(__pyx_k_Failed_to_create_compression_con), 0, 1, 0, 0},
  {&__pyx_n_s_FastWARCError, __pyx_k_FastWARCError, sizeof(__pyx_k_FastWARCError), 0, 0, 1, 1},
  {&__pyx_kp_s_FastWARC_reader_stale_error, __pyx_k_FastWARC_reader_stale_error, sizeof(__pyx_k_FastWARC_reader_stale_error), 0, 0, 1, 0},
  {&__pyx_kp_s_FastWARC_stream_error, __pyx_k_FastWARC_stream_error, sizeof(__pyx_k_FastWARC_stream_error), 0, 0, 1, 0},
  {&__pyx_n_s_FileStream, __pyx_k_FileStream, sizeof(__pyx_k_FileStream), 0, 0, 1, 1},
  {&__pyx_n_s_GZipStream, __pyx_k_GZipStream, sizeof(__pyx_k_GZipStream), 0, 0, 1, 1},
  {&__pyx_kp_s_Generic_FastWARC_exception, __pyx_k_Generic_FastWARC_exception, sizeof(__pyx_k_Generic_FastWARC_exception), 0, 0, 1, 0},
  {&__pyx_n_s_IOStream, __pyx_k_IOStream, sizeof(__pyx_k_IOStream), 0, 0, 1, 1},
  {&__pyx_n_s_LZ4Stream, __pyx_k_LZ4Stream, sizeof(__pyx_k_LZ4Stream), 0, 0, 1, 1},
  {&__pyx_kp_u_Not_a_valid_Brotli_stream, __pyx_k_Not_a_valid_Brotli_stream, sizeof(__pyx_k_Not_a_valid_Brotli_stream), 0, 1, 0, 0},
  {&__pyx_kp_u_Not_a_valid_GZip_stream, __pyx_k_Not_a_valid_GZip_stream, sizeof(__pyx_k_Not_a_valid_GZip_stream), 0, 1, 0, 0},
  {&__pyx_kp_u_Not_a_valid_LZ4_stream, __pyx_k_Not_a_valid_LZ4_stream, sizeof(__pyx_k_Not_a_valid_LZ4_stream), 0, 1, 0, 0},
  {&__pyx_kp_u_Not_a_valid_WARC_stream, __pyx_k_Not_a_valid_WARC_stream, sizeof(__pyx_k_Not_a_valid_WARC_stream), 0, 1, 0, 0},
  {&__pyx_kp_u_Object_of_type, __pyx_k_Object_of_type, sizeof(__pyx_k_Object_of_type), 0, 1, 0, 0},
  {&__pyx_n_s_PythonIOStreamAdapter, __pyx_k_PythonIOStreamAdapter, sizeof(__pyx_k_PythonIOStreamAdapter), 0, 0, 1, 1},
  {&__pyx_n_s_ReaderStaleError, __pyx_k_ReaderStaleError, sizeof(__pyx_k_ReaderStaleError), 0, 0, 1, 1},
  {&__pyx_n_s_StreamError, __pyx_k_StreamError, sizeof(__pyx_k_StreamError), 0, 0, 1, 1},
  {&__pyx_kp_u_Trying_I_O_on_closed_file, __pyx_k_Trying_I_O_on_closed_file, sizeof(__pyx_k_Trying_I_O_on_closed_file), 0, 1, 0, 0},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_n_s_brotli, __pyx_k_brotli, sizeof(__pyx_k_brotli), 0, 0, 1, 1},
  {&__pyx_n_s_buf, __pyx_k_buf, sizeof(__pyx_k_buf), 0, 0, 1, 1},
  {&__pyx_n_s_buf_reader_py_test_detect_strea, __pyx_k_buf_reader_py_test_detect_strea, sizeof(__pyx_k_buf_reader_py_test_detect_strea), 0, 0, 1, 1},
  {&__pyx_n_s_buf_reader_py_test_reset_limit, __pyx_k_buf_reader_py_test_reset_limit, sizeof(__pyx_k_buf_reader_py_test_reset_limit), 0, 0, 1, 1},
  {&__pyx_n_s_buf_reader_py_test_set_limit, __pyx_k_buf_reader_py_test_set_limit, sizeof(__pyx_k_buf_reader_py_test_set_limit), 0, 0, 1, 1},
  {&__pyx_n_s_buf_size, __pyx_k_buf_size, sizeof(__pyx_k_buf_size), 0, 0, 1, 1},
  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_compression_level, __pyx_k_compression_level, sizeof(__pyx_k_compression_level), 0, 0, 1, 1},
  {&__pyx_n_s_consume, __pyx_k_consume, sizeof(__pyx_k_consume), 0, 0, 1, 1},
  {&__pyx_n_s_crlf, __pyx_k_crlf, sizeof(__pyx_k_crlf), 0, 0, 1, 1},
  {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1},
  {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
  {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1},
  {&__pyx_n_s_exc_tb, __pyx_k_exc_tb, sizeof(__pyx_k_exc_tb), 0, 0, 1, 1},
  {&__pyx_n_s_exc_type, __pyx_k_exc_type, sizeof(__pyx_k_exc_type), 0, 0, 1, 1},
  {&__pyx_n_s_exc_val, __pyx_k_exc_val, sizeof(__pyx_k_exc_val), 0, 0, 1, 1},
  {&__pyx_n_s_fastwarc_stream_io, __pyx_k_fastwarc_stream_io, sizeof(__pyx_k_fastwarc_stream_io), 0, 0, 1, 1},
  {&__pyx_kp_s_fastwarc_stream_io_pyx, __pyx_k_fastwarc_stream_io_pyx, sizeof(__pyx_k_fastwarc_stream_io_pyx), 0, 0, 1, 0},
  {&__pyx_n_s_favor_dec_speed, __pyx_k_favor_dec_speed, sizeof(__pyx_k_favor_dec_speed), 0, 0, 1, 1},
  {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1},
  {&__pyx_n_s_finish, __pyx_k_finish, sizeof(__pyx_k_finish), 0, 0, 1, 1},
  {&__pyx_n_s_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_initial_data, __pyx_k_initial_data, sizeof(__pyx_k_initial_data), 0, 0, 1, 1},
  {&__pyx_n_s_io_stream_py_test_close, __pyx_k_io_stream_py_test_close, sizeof(__pyx_k_io_stream_py_test_close), 0, 0, 1, 1},
  {&__pyx_n_s_io_stream_py_test_flush, __pyx_k_io_stream_py_test_flush, sizeof(__pyx_k_io_stream_py_test_flush), 0, 0, 1, 1},
  {&__pyx_n_s_io_stream_py_test_read, __pyx_k_io_stream_py_test_read, sizeof(__pyx_k_io_stream_py_test_read), 0, 0, 1, 1},
  {&__pyx_n_s_io_stream_py_test_seek, __pyx_k_io_stream_py_test_seek, sizeof(__pyx_k_io_stream_py_test_seek), 0, 0, 1, 1},
  {&__pyx_n_s_io_stream_py_test_tell, __pyx_k_io_stream_py_test_tell, sizeof(__pyx_k_io_stream_py_test_tell), 0, 0, 1, 1},
  {&__pyx_n_s_io_stream_py_test_write, __pyx_k_io_stream_py_test_write, sizeof(__pyx_k_io_stream_py_test_write), 0, 0, 1, 1},
  {&__pyx_kp_u_is_not_a_valid_stream, __pyx_k_is_not_a_valid_stream, sizeof(__pyx_k_is_not_a_valid_stream), 0, 1, 0, 0},
  {&__pyx_n_s_lgblock, __pyx_k_lgblock, sizeof(__pyx_k_lgblock), 0, 0, 1, 1},
  {&__pyx_n_s_lgwin, __pyx_k_lgwin, sizeof(__pyx_k_lgwin), 0, 0, 1, 1},
  {&__pyx_n_s_limit, __pyx_k_limit, sizeof(__pyx_k_limit), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_max_line_len, __pyx_k_max_line_len, sizeof(__pyx_k_max_line_len), 0, 0, 1, 1},
  {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1},
  {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_negotiate_stream, __pyx_k_negotiate_stream, sizeof(__pyx_k_negotiate_stream), 0, 0, 1, 1},
  {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1},
  {&__pyx_n_s_offset, __pyx_k_offset, sizeof(__pyx_k_offset), 0, 0, 1, 1},
  {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
  {&__pyx_n_s_process, __pyx_k_process, sizeof(__pyx_k_process), 0, 0, 1, 1},
  {&__pyx_n_s_py_stream, __pyx_k_py_stream, sizeof(__pyx_k_py_stream), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_quality, __pyx_k_quality, sizeof(__pyx_k_quality), 0, 0, 1, 1},
  {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
  {&__pyx_n_s_raw_stream, __pyx_k_raw_stream, sizeof(__pyx_k_raw_stream), 0, 0, 1, 1},
  {&__pyx_n_u_rb, __pyx_k_rb, sizeof(__pyx_k_rb), 0, 1, 0, 1},
  {&__pyx_n_s_read, __pyx_k_read, sizeof(__pyx_k_read), 0, 0, 1, 1},
  {&__pyx_n_u_read, __pyx_k_read, sizeof(__pyx_k_read), 0, 1, 0, 1},
  {&__pyx_n_s_readline, __pyx_k_readline, sizeof(__pyx_k_readline), 0, 0, 1, 1},
  {&__pyx_n_s_seek, __pyx_k_seek, sizeof(__pyx_k_seek), 0, 0, 1, 1},
  {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1},
  {&__pyx_n_s_stream, __pyx_k_stream, sizeof(__pyx_k_stream), 0, 0, 1, 1},
  {&__pyx_n_s_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
  {&__pyx_n_s_zlib, __pyx_k_zlib, sizeof(__pyx_k_zlib), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 61, __pyx_L1_error)
  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(1, 290, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "fastwarc/stream_io.pyx":151
 *     cdef size_t tell(self) except -1:
 *         if self.pos == strnpos:
 *             raise ValueError('Trying I/O on closed file.')             # <<<<<<<<<<<<<<
 *         return self.pos
 * 
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Trying_I_O_on_closed_file); if (unlikely(!__pyx_tuple_)) __PYX_ERR(1, 151, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "fastwarc/stream_io.pyx":73
 * 
 * 
 * def _io_stream_py_test_read(IOStream stream, size_t size):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_read(stream, size)
 */
  __pyx_tuple__6 = PyTuple_Pack(3, __pyx_n_s_stream, __pyx_n_s_size, __pyx_n_s_buf); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(1, 73, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);
  __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_io_stream_py_test_read, 73, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(1, 73, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":84
 * 
 * 
 * def _io_stream_py_test_write(IOStream stream, bytes data):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_write(stream, data)
 */
  __pyx_tuple__8 = PyTuple_Pack(3, __pyx_n_s_stream, __pyx_n_s_data, __pyx_n_s_size); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(1, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);
  __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_io_stream_py_test_write, 84, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(1, 84, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":94
 * 
 * 
 * def _io_stream_py_test_tell(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_tell(stream)
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_n_s_stream); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(1, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);
  __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_io_stream_py_test_tell, 94, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(1, 94, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":103
 * 
 * 
 * def _io_stream_py_test_seek(IOStream stream, size_t offset):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_seek(stream, offset)
 */
  __pyx_tuple__12 = PyTuple_Pack(2, __pyx_n_s_stream, __pyx_n_s_offset); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(1, 103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);
  __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_io_stream_py_test_seek, 103, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(1, 103, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":112
 * 
 * 
 * def _io_stream_py_test_flush(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_flush(stream)
 */
  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_n_s_stream); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(1, 112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);
  __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_io_stream_py_test_flush, 112, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(1, 112, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":121
 * 
 * 
 * def _io_stream_py_test_close(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_close(stream)
 */
  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_n_s_stream); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(1, 121, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);
  __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_io_stream_py_test_close, 121, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(1, 121, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":1081
 * 
 * 
 * def _buf_reader_py_test_detect_stream_type(BufferedReader buf):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_detect_stream_type(buf):
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_n_s_buf); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(1, 1081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);
  __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_buf_reader_py_test_detect_strea, 1081, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(1, 1081, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":1090
 * 
 * 
 * def _buf_reader_py_test_set_limit(BufferedReader buf, size_t limit):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_detect_set_limit(buf, limit):
 */
  __pyx_tuple__20 = PyTuple_Pack(2, __pyx_n_s_buf, __pyx_n_s_limit); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(1, 1090, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);
  __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_buf_reader_py_test_set_limit, 1090, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(1, 1090, __pyx_L1_error)

  /* "fastwarc/stream_io.pyx":1099
 * 
 * 
 * def _buf_reader_py_test_reset_limit(BufferedReader buf):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_reset_limit(buf, limit):
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_n_s_buf); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(1, 1099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);
  __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fastwarc_stream_io_pyx, __pyx_n_s_buf_reader_py_test_reset_limit, 1099, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(1, 1099, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(1, 1, __pyx_L1_error);
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __pyx_vtabptr_8fastwarc_9stream_io_IOStream = &__pyx_vtable_8fastwarc_9stream_io_IOStream;
  __pyx_vtable_8fastwarc_9stream_io_IOStream.read = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char *, size_t))__pyx_f_8fastwarc_9stream_io_8IOStream_read;
  __pyx_vtable_8fastwarc_9stream_io_IOStream.write = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char const *, size_t))__pyx_f_8fastwarc_9stream_io_8IOStream_write;
  __pyx_vtable_8fastwarc_9stream_io_IOStream.tell = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_8IOStream_tell;
  __pyx_vtable_8fastwarc_9stream_io_IOStream.seek = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, size_t))__pyx_f_8fastwarc_9stream_io_8IOStream_seek;
  __pyx_vtable_8fastwarc_9stream_io_IOStream.flush = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_8IOStream_flush;
  __pyx_vtable_8fastwarc_9stream_io_IOStream.close = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_8IOStream_close;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_IOStream) < 0) __PYX_ERR(1, 42, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_IOStream.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_IOStream.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_IOStream.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_IOStream.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_IOStream.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_IOStream) < 0) __PYX_ERR(1, 42, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IOStream, (PyObject *)&__pyx_type_8fastwarc_9stream_io_IOStream) < 0) __PYX_ERR(1, 42, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_IOStream = &__pyx_type_8fastwarc_9stream_io_IOStream;
  __pyx_vtabptr_8fastwarc_9stream_io_PythonIOStreamAdapter = &__pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter;
  __pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter.__pyx_base = *__pyx_vtabptr_8fastwarc_9stream_io_IOStream;
  __pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter.__pyx_base.read = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char *, size_t))__pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_read;
  __pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter.__pyx_base.write = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char const *, size_t))__pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_write;
  __pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter.__pyx_base.tell = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_tell;
  __pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter.__pyx_base.seek = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, size_t))__pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_seek;
  __pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter.__pyx_base.flush = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_flush;
  __pyx_vtable_8fastwarc_9stream_io_PythonIOStreamAdapter.__pyx_base.close = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_21PythonIOStreamAdapter_close;
  __pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter.tp_base = __pyx_ptype_8fastwarc_9stream_io_IOStream;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter) < 0) __PYX_ERR(1, 261, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_PythonIOStreamAdapter) < 0) __PYX_ERR(1, 261, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_PythonIOStreamAdapter, (PyObject *)&__pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter) < 0) __PYX_ERR(1, 261, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_PythonIOStreamAdapter = &__pyx_type_8fastwarc_9stream_io_PythonIOStreamAdapter;
  __pyx_vtabptr_8fastwarc_9stream_io_BytesIOStream = &__pyx_vtable_8fastwarc_9stream_io_BytesIOStream;
  __pyx_vtable_8fastwarc_9stream_io_BytesIOStream.__pyx_base = *__pyx_vtabptr_8fastwarc_9stream_io_IOStream;
  __pyx_vtable_8fastwarc_9stream_io_BytesIOStream.__pyx_base.read = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char *, size_t))__pyx_f_8fastwarc_9stream_io_13BytesIOStream_read;
  __pyx_vtable_8fastwarc_9stream_io_BytesIOStream.__pyx_base.write = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char const *, size_t))__pyx_f_8fastwarc_9stream_io_13BytesIOStream_write;
  __pyx_vtable_8fastwarc_9stream_io_BytesIOStream.__pyx_base.tell = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_13BytesIOStream_tell;
  __pyx_vtable_8fastwarc_9stream_io_BytesIOStream.__pyx_base.seek = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, size_t))__pyx_f_8fastwarc_9stream_io_13BytesIOStream_seek;
  __pyx_vtable_8fastwarc_9stream_io_BytesIOStream.__pyx_base.close = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_13BytesIOStream_close;
  __pyx_vtable_8fastwarc_9stream_io_BytesIOStream.getvalue = (std::string (*)(struct __pyx_obj_8fastwarc_9stream_io_BytesIOStream *))__pyx_f_8fastwarc_9stream_io_13BytesIOStream_getvalue;
  __pyx_type_8fastwarc_9stream_io_BytesIOStream.tp_base = __pyx_ptype_8fastwarc_9stream_io_IOStream;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_BytesIOStream) < 0) __PYX_ERR(1, 132, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_BytesIOStream.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_BytesIOStream.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_BytesIOStream.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_BytesIOStream.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_BytesIOStream.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_BytesIOStream) < 0) __PYX_ERR(1, 132, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BytesIOStream, (PyObject *)&__pyx_type_8fastwarc_9stream_io_BytesIOStream) < 0) __PYX_ERR(1, 132, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_BytesIOStream = &__pyx_type_8fastwarc_9stream_io_BytesIOStream;
  __pyx_vtabptr_8fastwarc_9stream_io_FileStream = &__pyx_vtable_8fastwarc_9stream_io_FileStream;
  __pyx_vtable_8fastwarc_9stream_io_FileStream.__pyx_base = *__pyx_vtabptr_8fastwarc_9stream_io_IOStream;
  __pyx_vtable_8fastwarc_9stream_io_FileStream.__pyx_base.read = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char *, size_t))__pyx_f_8fastwarc_9stream_io_10FileStream_read;
  __pyx_vtable_8fastwarc_9stream_io_FileStream.__pyx_base.write = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char const *, size_t))__pyx_f_8fastwarc_9stream_io_10FileStream_write;
  __pyx_vtable_8fastwarc_9stream_io_FileStream.__pyx_base.tell = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_10FileStream_tell;
  __pyx_vtable_8fastwarc_9stream_io_FileStream.__pyx_base.seek = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, size_t))__pyx_f_8fastwarc_9stream_io_10FileStream_seek;
  __pyx_vtable_8fastwarc_9stream_io_FileStream.__pyx_base.flush = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_10FileStream_flush;
  __pyx_vtable_8fastwarc_9stream_io_FileStream.__pyx_base.close = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_10FileStream_close;
  __pyx_vtable_8fastwarc_9stream_io_FileStream.open = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_FileStream *, char const *, struct __pyx_opt_args_8fastwarc_9stream_io_10FileStream_open *__pyx_optional_args))__pyx_f_8fastwarc_9stream_io_10FileStream_open;
  __pyx_type_8fastwarc_9stream_io_FileStream.tp_base = __pyx_ptype_8fastwarc_9stream_io_IOStream;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_FileStream) < 0) __PYX_ERR(1, 189, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_FileStream.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_FileStream.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_FileStream.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_FileStream.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_FileStream.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_FileStream) < 0) __PYX_ERR(1, 189, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_FileStream, (PyObject *)&__pyx_type_8fastwarc_9stream_io_FileStream) < 0) __PYX_ERR(1, 189, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_FileStream = &__pyx_type_8fastwarc_9stream_io_FileStream;
  __pyx_vtabptr_8fastwarc_9stream_io_CompressingStream = &__pyx_vtable_8fastwarc_9stream_io_CompressingStream;
  __pyx_vtable_8fastwarc_9stream_io_CompressingStream.__pyx_base = *__pyx_vtabptr_8fastwarc_9stream_io_IOStream;
  __pyx_vtable_8fastwarc_9stream_io_CompressingStream.begin_member = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *))__pyx_f_8fastwarc_9stream_io_17CompressingStream_begin_member;
  __pyx_vtable_8fastwarc_9stream_io_CompressingStream.end_member = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *))__pyx_f_8fastwarc_9stream_io_17CompressingStream_end_member;
  __pyx_type_8fastwarc_9stream_io_CompressingStream.tp_base = __pyx_ptype_8fastwarc_9stream_io_IOStream;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_CompressingStream) < 0) __PYX_ERR(1, 297, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_CompressingStream.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_CompressingStream.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_CompressingStream.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_CompressingStream.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_CompressingStream.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_CompressingStream) < 0) __PYX_ERR(1, 297, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_CompressingStream, (PyObject *)&__pyx_type_8fastwarc_9stream_io_CompressingStream) < 0) __PYX_ERR(1, 297, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_CompressingStream = &__pyx_type_8fastwarc_9stream_io_CompressingStream;
  __pyx_vtabptr_8fastwarc_9stream_io_GZipStream = &__pyx_vtable_8fastwarc_9stream_io_GZipStream;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.__pyx_base = *__pyx_vtabptr_8fastwarc_9stream_io_CompressingStream;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.__pyx_base.__pyx_base.read = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char *, size_t))__pyx_f_8fastwarc_9stream_io_10GZipStream_read;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.__pyx_base.__pyx_base.write = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char const *, size_t))__pyx_f_8fastwarc_9stream_io_10GZipStream_write;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.__pyx_base.__pyx_base.tell = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_10GZipStream_tell;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.__pyx_base.__pyx_base.flush = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_10GZipStream_flush;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.__pyx_base.__pyx_base.close = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_10GZipStream_close;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.__pyx_base.begin_member = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *))__pyx_f_8fastwarc_9stream_io_10GZipStream_begin_member;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.__pyx_base.end_member = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *))__pyx_f_8fastwarc_9stream_io_10GZipStream_end_member;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream.prepopulate = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *, int, std::string const &))__pyx_f_8fastwarc_9stream_io_10GZipStream_prepopulate;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream._init_z_stream = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *, int))__pyx_f_8fastwarc_9stream_io_10GZipStream__init_z_stream;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream._free_z_stream = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *))__pyx_f_8fastwarc_9stream_io_10GZipStream__free_z_stream;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream._reinit_z_stream = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *, int))__pyx_f_8fastwarc_9stream_io_10GZipStream__reinit_z_stream;
  __pyx_vtable_8fastwarc_9stream_io_GZipStream._refill_working_buf = (int (*)(struct __pyx_obj_8fastwarc_9stream_io_GZipStream *, size_t))__pyx_f_8fastwarc_9stream_io_10GZipStream__refill_working_buf;
  __pyx_type_8fastwarc_9stream_io_GZipStream.tp_base = __pyx_ptype_8fastwarc_9stream_io_CompressingStream;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_GZipStream) < 0) __PYX_ERR(1, 311, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_GZipStream.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_GZipStream.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_GZipStream.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_GZipStream.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_GZipStream.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_GZipStream) < 0) __PYX_ERR(1, 311, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_GZipStream, (PyObject *)&__pyx_type_8fastwarc_9stream_io_GZipStream) < 0) __PYX_ERR(1, 311, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_GZipStream = &__pyx_type_8fastwarc_9stream_io_GZipStream;
  __pyx_vtabptr_8fastwarc_9stream_io_LZ4Stream = &__pyx_vtable_8fastwarc_9stream_io_LZ4Stream;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.__pyx_base = *__pyx_vtabptr_8fastwarc_9stream_io_CompressingStream;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.__pyx_base.__pyx_base.read = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char *, size_t))__pyx_f_8fastwarc_9stream_io_9LZ4Stream_read;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.__pyx_base.__pyx_base.write = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char const *, size_t))__pyx_f_8fastwarc_9stream_io_9LZ4Stream_write;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.__pyx_base.__pyx_base.tell = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_9LZ4Stream_tell;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.__pyx_base.__pyx_base.flush = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_9LZ4Stream_flush;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.__pyx_base.__pyx_base.close = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_9LZ4Stream_close;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.__pyx_base.begin_member = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *))__pyx_f_8fastwarc_9stream_io_9LZ4Stream_begin_member;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.__pyx_base.end_member = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *))__pyx_f_8fastwarc_9stream_io_9LZ4Stream_end_member;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream.prepopulate = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *, std::string const &))__pyx_f_8fastwarc_9stream_io_9LZ4Stream_prepopulate;
  __pyx_vtable_8fastwarc_9stream_io_LZ4Stream._free_ctx = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_LZ4Stream *))__pyx_f_8fastwarc_9stream_io_9LZ4Stream__free_ctx;
  __pyx_type_8fastwarc_9stream_io_LZ4Stream.tp_base = __pyx_ptype_8fastwarc_9stream_io_CompressingStream;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_LZ4Stream) < 0) __PYX_ERR(1, 550, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_LZ4Stream.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_LZ4Stream.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_LZ4Stream.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_LZ4Stream.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_LZ4Stream.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_LZ4Stream) < 0) __PYX_ERR(1, 550, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_LZ4Stream, (PyObject *)&__pyx_type_8fastwarc_9stream_io_LZ4Stream) < 0) __PYX_ERR(1, 550, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_LZ4Stream = &__pyx_type_8fastwarc_9stream_io_LZ4Stream;
  __pyx_vtabptr_8fastwarc_9stream_io_BrotliStream = &__pyx_vtable_8fastwarc_9stream_io_BrotliStream;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base = *__pyx_vtabptr_8fastwarc_9stream_io_CompressingStream;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base.__pyx_base.read = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char *, size_t))__pyx_f_8fastwarc_9stream_io_12BrotliStream_read;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base.__pyx_base.write = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, char const *, size_t))__pyx_f_8fastwarc_9stream_io_12BrotliStream_write;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base.__pyx_base.tell = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_12BrotliStream_tell;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base.__pyx_base.seek = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *, size_t))__pyx_f_8fastwarc_9stream_io_12BrotliStream_seek;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base.__pyx_base.flush = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_12BrotliStream_flush;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base.__pyx_base.close = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_IOStream *))__pyx_f_8fastwarc_9stream_io_12BrotliStream_close;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base.begin_member = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *))__pyx_f_8fastwarc_9stream_io_12BrotliStream_begin_member;
  __pyx_vtable_8fastwarc_9stream_io_BrotliStream.__pyx_base.end_member = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_CompressingStream *))__pyx_f_8fastwarc_9stream_io_12BrotliStream_end_member;
  __pyx_type_8fastwarc_9stream_io_BrotliStream.tp_base = __pyx_ptype_8fastwarc_9stream_io_CompressingStream;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_BrotliStream) < 0) __PYX_ERR(1, 716, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_BrotliStream.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_BrotliStream.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_BrotliStream.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_BrotliStream.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_BrotliStream.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_BrotliStream) < 0) __PYX_ERR(1, 716, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BrotliStream, (PyObject *)&__pyx_type_8fastwarc_9stream_io_BrotliStream) < 0) __PYX_ERR(1, 716, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_BrotliStream = &__pyx_type_8fastwarc_9stream_io_BrotliStream;
  __pyx_vtabptr_8fastwarc_9stream_io_BufferedReader = &__pyx_vtable_8fastwarc_9stream_io_BufferedReader;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader.set_limit = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, size_t))__pyx_f_8fastwarc_9stream_io_14BufferedReader_set_limit;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader.reset_limit = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *))__pyx_f_8fastwarc_9stream_io_14BufferedReader_reset_limit;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader.detect_stream_type = (int (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *))__pyx_f_8fastwarc_9stream_io_14BufferedReader_detect_stream_type;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader.read = (std::string (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_read *__pyx_optional_args))__pyx_f_8fastwarc_9stream_io_14BufferedReader_read;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader.readline = (std::string (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_readline *__pyx_optional_args))__pyx_f_8fastwarc_9stream_io_14BufferedReader_readline;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader.tell = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch))__pyx_f_8fastwarc_9stream_io_14BufferedReader_tell;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader.consume = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch, struct __pyx_opt_args_8fastwarc_9stream_io_14BufferedReader_consume *__pyx_optional_args))__pyx_f_8fastwarc_9stream_io_14BufferedReader_consume;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader.close = (void (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, int __pyx_skip_dispatch))__pyx_f_8fastwarc_9stream_io_14BufferedReader_close;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader._fill_buf = (int (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *))__pyx_f_8fastwarc_9stream_io_14BufferedReader__fill_buf;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader._get_buf = (std::string_view *(*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *))__pyx_f_8fastwarc_9stream_io_14BufferedReader__get_buf;
  __pyx_vtable_8fastwarc_9stream_io_BufferedReader._consume_buf = (size_t (*)(struct __pyx_obj_8fastwarc_9stream_io_BufferedReader *, size_t))__pyx_f_8fastwarc_9stream_io_14BufferedReader__consume_buf;
  if (PyType_Ready(&__pyx_type_8fastwarc_9stream_io_BufferedReader) < 0) __PYX_ERR(1, 806, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_8fastwarc_9stream_io_BufferedReader.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_8fastwarc_9stream_io_BufferedReader.tp_dictoffset && __pyx_type_8fastwarc_9stream_io_BufferedReader.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_8fastwarc_9stream_io_BufferedReader.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_8fastwarc_9stream_io_BufferedReader.tp_dict, __pyx_vtabptr_8fastwarc_9stream_io_BufferedReader) < 0) __PYX_ERR(1, 806, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BufferedReader, (PyObject *)&__pyx_type_8fastwarc_9stream_io_BufferedReader) < 0) __PYX_ERR(1, 806, __pyx_L1_error)
  __pyx_ptype_8fastwarc_9stream_io_BufferedReader = &__pyx_type_8fastwarc_9stream_io_BufferedReader;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}


#ifndef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#elif PY_MAJOR_VERSION < 3
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" void
#else
#define __Pyx_PyMODINIT_FUNC void
#endif
#else
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyObject *
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC initstream_io(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC initstream_io(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_stream_io(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_stream_io(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    #if PY_VERSION_HEX >= 0x030700A1
    static PY_INT64_T main_interpreter_id = -1;
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return (unlikely(current_id == -1)) ? -1 : 0;
    } else if (unlikely(main_interpreter_id != current_id))
    #else
    static PyInterpreterState *main_interpreter = NULL;
    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
    if (!main_interpreter) {
        main_interpreter = current_interpreter;
    } else if (unlikely(main_interpreter != current_interpreter))
    #endif
    {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
            result = PyDict_SetItemString(moddict, to_name, value);
        }
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    if (__Pyx_check_single_interpreter())
        return NULL;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static CYTHON_SMALL_CODE int __pyx_pymod_exec_stream_io(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m) {
    if (__pyx_m == __pyx_pyinit_module) return 0;
    PyErr_SetString(PyExc_RuntimeError, "Module 'stream_io' has already been imported. Re-initialisation is not supported.");
    return -1;
  }
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  #if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
  PyErr_Clear();
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  if (!__Pyx_RefNanny)
      Py_FatalError("failed to import 'refnanny' module");
}
#endif
  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_stream_io(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(1, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(1, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(1, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_AsyncGen_USED
  if (__pyx_AsyncGen_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  PyEval_InitThreads();
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("stream_io", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(1, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(1, 1, __pyx_L1_error)
  Py_INCREF(__pyx_b);
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(1, 1, __pyx_L1_error)
  Py_INCREF(__pyx_cython_runtime);
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(1, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_fastwarc__stream_io) {
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(1, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "fastwarc.stream_io")) {
      if (unlikely(PyDict_SetItemString(modules, "fastwarc.stream_io", __pyx_m) < 0)) __PYX_ERR(1, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  (void)__Pyx_modinit_variable_export_code();
  (void)__Pyx_modinit_function_export_code();
  if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(1, 1, __pyx_L1_error)
  (void)__Pyx_modinit_type_import_code();
  (void)__Pyx_modinit_variable_import_code();
  (void)__Pyx_modinit_function_import_code();
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  #endif

  /* "fastwarc/stream_io.pyx":26
 * from resiliparse_inc.stdio cimport fclose, ferror, fflush, fopen, fread, fseek, ftell, fwrite, SEEK_SET
 * 
 * import brotli             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_brotli, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_brotli, __pyx_t_1) < 0) __PYX_ERR(1, 26, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":29
 * 
 * 
 * class FastWARCError(Exception):             # <<<<<<<<<<<<<<
 *     """Generic FastWARC exception."""
 * 
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 29, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
  __Pyx_GIVEREF(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
  __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 29, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_t_1, __pyx_n_s_FastWARCError, __pyx_n_s_FastWARCError, (PyObject *) NULL, __pyx_n_s_fastwarc_stream_io, __pyx_kp_s_Generic_FastWARC_exception); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 29, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_FastWARCError, __pyx_t_1, __pyx_t_3, NULL, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 29, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_FastWARCError, __pyx_t_4) < 0) __PYX_ERR(1, 29, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":33
 * 
 * 
 * class StreamError(FastWARCError):             # <<<<<<<<<<<<<<
 *     """FastWARC stream error."""
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_FastWARCError); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_CalculateMetaclass(NULL, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_Py3MetaclassPrepare(__pyx_t_1, __pyx_t_2, __pyx_n_s_StreamError, __pyx_n_s_StreamError, (PyObject *) NULL, __pyx_n_s_fastwarc_stream_io, __pyx_kp_s_FastWARC_stream_error); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_1, __pyx_n_s_StreamError, __pyx_t_2, __pyx_t_3, NULL, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_StreamError, __pyx_t_4) < 0) __PYX_ERR(1, 33, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "fastwarc/stream_io.pyx":37
 * 
 * 
 * class ReaderStaleError(FastWARCError):             # <<<<<<<<<<<<<<
 *     """FastWARC reader stale error."""
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_FastWARCError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_t_1, __pyx_n_s_ReaderStaleError, __pyx_n_s_ReaderStaleError, (PyObject *) NULL, __pyx_n_s_fastwarc_stream_io, __pyx_kp_s_FastWARC_reader_stale_error); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_ReaderStaleError, __pyx_t_1, __pyx_t_3, NULL, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ReaderStaleError, __pyx_t_4) < 0) __PYX_ERR(1, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":73
 * 
 * 
 * def _io_stream_py_test_read(IOStream stream, size_t size):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_read(stream, size)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_1_io_stream_py_test_read, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 73, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_io_stream_py_test_read, __pyx_t_1) < 0) __PYX_ERR(1, 73, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":84
 * 
 * 
 * def _io_stream_py_test_write(IOStream stream, bytes data):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_write(stream, data)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_3_io_stream_py_test_write, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_io_stream_py_test_write, __pyx_t_1) < 0) __PYX_ERR(1, 84, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":94
 * 
 * 
 * def _io_stream_py_test_tell(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_tell(stream)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_5_io_stream_py_test_tell, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_io_stream_py_test_tell, __pyx_t_1) < 0) __PYX_ERR(1, 94, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":103
 * 
 * 
 * def _io_stream_py_test_seek(IOStream stream, size_t offset):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_seek(stream, offset)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_7_io_stream_py_test_seek, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_io_stream_py_test_seek, __pyx_t_1) < 0) __PYX_ERR(1, 103, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":112
 * 
 * 
 * def _io_stream_py_test_flush(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_flush(stream)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_9_io_stream_py_test_flush, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 112, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_io_stream_py_test_flush, __pyx_t_1) < 0) __PYX_ERR(1, 112, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":121
 * 
 * 
 * def _io_stream_py_test_close(IOStream stream):             # <<<<<<<<<<<<<<
 *     """
 *     io_stream_py_test_close(stream)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_11_io_stream_py_test_close, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 121, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_io_stream_py_test_close, __pyx_t_1) < 0) __PYX_ERR(1, 121, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":327
 *         pass
 * 
 *     def __cinit__(self, raw_stream, compression_level=Z_BEST_COMPRESSION, bint zlib=False):             # <<<<<<<<<<<<<<
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.member_started = False
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(Z_BEST_COMPRESSION); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 327, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__2 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":566
 *         pass
 * 
 *     def __cinit__(self, raw_stream, compression_level=LZ4HC_CLEVEL_MAX, favor_dec_speed=True):             # <<<<<<<<<<<<<<
 *         self.raw_stream = wrap_stream(raw_stream)
 *         self.cctx = NULL
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(LZ4HC_CLEVEL_MAX); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 566, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k__3 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":939
 *         self.limit = strnpos
 * 
 *     cpdef string read(self, size_t size=strnpos) except *:             # <<<<<<<<<<<<<<
 *         """
 *         read(self, size=-1)
 */
  __pyx_k__4 = std::string::npos;
  __pyx_k__4 = std::string::npos;

  /* "fastwarc/stream_io.pyx":1045
 *         return self.stream.tell() - self.buf_view.size()
 * 
 *     cpdef size_t consume(self, size_t size=strnpos) except -1:             # <<<<<<<<<<<<<<
 *         """
 *         consume(self, size=-1)
 */
  __pyx_k__5 = std::string::npos;
  __pyx_k__5 = std::string::npos;

  /* "fastwarc/stream_io.pyx":1081
 * 
 * 
 * def _buf_reader_py_test_detect_stream_type(BufferedReader buf):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_detect_stream_type(buf):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_15_buf_reader_py_test_detect_stream_type, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_buf_reader_py_test_detect_strea, __pyx_t_1) < 0) __PYX_ERR(1, 1081, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":1090
 * 
 * 
 * def _buf_reader_py_test_set_limit(BufferedReader buf, size_t limit):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_detect_set_limit(buf, limit):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_17_buf_reader_py_test_set_limit, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1090, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_buf_reader_py_test_set_limit, __pyx_t_1) < 0) __PYX_ERR(1, 1090, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":1099
 * 
 * 
 * def _buf_reader_py_test_reset_limit(BufferedReader buf):             # <<<<<<<<<<<<<<
 *     """
 *     _buf_reader_py_test_reset_limit(buf, limit):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8fastwarc_9stream_io_19_buf_reader_py_test_reset_limit, NULL, __pyx_n_s_fastwarc_stream_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_buf_reader_py_test_reset_limit, __pyx_t_1) < 0) __PYX_ERR(1, 1099, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "fastwarc/stream_io.pyx":1
 * # Copyright 2021 Janek Bevendorff             # <<<<<<<<<<<<<<
 * #
 * # Licensed under the Apache License, Version 2.0 (the "License");
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "string.to_py":55
 * 
 * @cname("__pyx_convert_PyByteArray_string_to_py_std__in_string")
 * cdef inline object __pyx_convert_PyByteArray_string_to_py_std__in_string(const string& s):             # <<<<<<<<<<<<<<
 *     return __Pyx_PyByteArray_FromStringAndSize(s.data(), s.size())
 * 
 */

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init fastwarc.stream_io", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_CLEAR(__pyx_m);
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init fastwarc.stream_io");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule(modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, "RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#endif

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* RaiseArgTupleInvalid */
static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* ArgTypeTest */
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    else if (exact) {
        #if PY_MAJOR_VERSION == 2
        if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(__Pyx_TypeCheck(obj, type))) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

/* PyCFunctionFastCall */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    int flags = PyCFunction_GET_FLAGS(func);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
        return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
    }
}
#endif

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = Py_TYPE(func)->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
    if (likely(PyCFunction_Check(func))) {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (__Pyx_PyFastCFunction_Check(func)) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* KeywordStringCheck */
static int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CYTHON_COMPILING_IN_PYPY
    if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* RaiseException */
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause) {
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = __Pyx_PyThreadState_Current;
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* WriteUnraisableException */
static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* PyDictVersioning */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
    PyObject **dictptr = NULL;
    Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
    if (offset) {
#if CYTHON_COMPILING_IN_CPYTHON
        dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
#else
        dictptr = _PyObject_GetDictPtr(obj);
#endif
    }
    return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
}
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
        return 0;
    return obj_dict_version == __Pyx_get_object_dict_version(obj);
}
#endif

/* GetModuleGlobalName */
#if CYTHON_USE_DICT_VERSIONS
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
#else
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
#endif
{
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    } else if (unlikely(PyErr_Occurred())) {
        return NULL;
    }
#else
    result = PyDict_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* decode_c_string */
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
    Py_ssize_t length;
    if (unlikely((start < 0) | (stop < 0))) {
        size_t slen = strlen(cstring);
        if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) {
            PyErr_SetString(PyExc_OverflowError,
                            "c-string too long to convert to Python");
            return NULL;
        }
        length = (Py_ssize_t) slen;
        if (start < 0) {
            start += length;
            if (start < 0)
                start = 0;
        }
        if (stop < 0)
            stop += length;
    }
    if (unlikely(stop <= start))
        return __Pyx_NewRef(__pyx_empty_unicode);
    length = stop - start;
    cstring += start;
    if (decode_func) {
        return decode_func(cstring, length, errors);
    } else {
        return PyUnicode_Decode(cstring, length, encoding, errors);
    }
}

/* PyObjectCall2Args */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
    PyObject *args, *result = NULL;
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyFunction_FastCall(function, args, 2);
    }
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyCFunction_FastCall(function, args, 2);
    }
    #endif
    args = PyTuple_New(2);
    if (unlikely(!args)) goto done;
    Py_INCREF(arg1);
    PyTuple_SET_ITEM(args, 0, arg1);
    Py_INCREF(arg2);
    PyTuple_SET_ITEM(args, 1, arg2);
    Py_INCREF(function);
    result = __Pyx_PyObject_Call(function, args, NULL);
    Py_DECREF(args);
    Py_DECREF(function);
done:
    return result;
}

/* ExtTypeTest */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(__Pyx_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

/* GetAttr */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_USE_TYPE_SLOTS
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

/* HasAttr */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
    PyObject *r;
    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
        PyErr_SetString(PyExc_TypeError,
                        "hasattr(): attribute name must be string");
        return -1;
    }
    r = __Pyx_GetAttr(o, n);
    if (unlikely(!r)) {
        PyErr_Clear();
        return 0;
    } else {
        Py_DECREF(r);
        return 1;
    }
}

/* JoinPyUnicode */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      CYTHON_UNUSED Py_UCS4 max_char) {
#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    PyObject *result_uval;
    int result_ukind;
    Py_ssize_t i, char_pos;
    void *result_udata;
#if CYTHON_PEP393_ENABLED
    result_uval = PyUnicode_New(result_ulength, max_char);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
    result_udata = PyUnicode_DATA(result_uval);
#else
    result_uval = PyUnicode_FromUnicode(NULL, result_ulength);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = sizeof(Py_UNICODE);
    result_udata = PyUnicode_AS_UNICODE(result_uval);
#endif
    char_pos = 0;
    for (i=0; i < value_count; i++) {
        int ukind;
        Py_ssize_t ulength;
        void *udata;
        PyObject *uval = PyTuple_GET_ITEM(value_tuple, i);
        if (unlikely(__Pyx_PyUnicode_READY(uval)))
            goto bad;
        ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
        if (unlikely(!ulength))
            continue;
        if (unlikely(char_pos + ulength < 0))
            goto overflow;
        ukind = __Pyx_PyUnicode_KIND(uval);
        udata = __Pyx_PyUnicode_DATA(uval);
        if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) {
            memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind));
        } else {
            #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters)
            _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
            #else
            Py_ssize_t j;
            for (j=0; j < ulength; j++) {
                Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
                __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
            }
            #endif
        }
        char_pos += ulength;
    }
    return result_uval;
overflow:
    PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
bad:
    Py_DECREF(result_uval);
    return NULL;
#else
    result_ulength++;
    value_count++;
    return PyUnicode_Join(__pyx_empty_unicode, value_tuple);
#endif
}

/* PyObjectCallNoArg */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
#else
    if (likely(PyCFunction_Check(func)))
#endif
    {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* GetTopmostException */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem *
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
{
    _PyErr_StackItem *exc_info = tstate->exc_info;
    while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
           exc_info->previous_item != NULL)
    {
        exc_info = exc_info->previous_item;
    }
    return exc_info;
}
#endif

/* SaveResetException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    *type = exc_info->exc_type;
    *value = exc_info->exc_value;
    *tb = exc_info->exc_traceback;
    #else
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    #endif
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = type;
    exc_info->exc_value = value;
    exc_info->exc_traceback = tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = a->tp_base;
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
    if (!res) {
        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
    return res;
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    assert(PyExceptionClass_Check(exc_type));
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        #if PY_MAJOR_VERSION < 3
        if (likely(exc_type == t)) return 1;
        #endif
        if (likely(PyExceptionClass_Check(t))) {
            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
        } else {
        }
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        if (likely(PyExceptionClass_Check(exc_type))) {
            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
        } else if (likely(PyTuple_Check(exc_type))) {
            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
        } else {
        }
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    assert(PyExceptionClass_Check(exc_type1));
    assert(PyExceptionClass_Check(exc_type2));
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

/* GetException */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
#endif
{
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    #if CYTHON_USE_EXC_INFO_STACK
    {
        _PyErr_StackItem *exc_info = tstate->exc_info;
        tmp_type = exc_info->exc_type;
        tmp_value = exc_info->exc_value;
        tmp_tb = exc_info->exc_traceback;
        exc_info->exc_type = local_type;
        exc_info->exc_value = local_value;
        exc_info->exc_traceback = local_tb;
    }
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* PyErrExceptionMatches */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    if (unlikely(PyTuple_Check(err)))
        return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
    return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* CallNextTpTraverse */
static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) {
    PyTypeObject* type = Py_TYPE(obj);
    while (type && type->tp_traverse != current_tp_traverse)
        type = type->tp_base;
    while (type && type->tp_traverse == current_tp_traverse)
        type = type->tp_base;
    if (type && type->tp_traverse)
        return type->tp_traverse(obj, v, a);
    return 0;
}

/* CallNextTpClear */
static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
    PyTypeObject* type = Py_TYPE(obj);
    while (type && type->tp_clear != current_tp_clear)
        type = type->tp_base;
    while (type && type->tp_clear == current_tp_clear)
        type = type->tp_base;
    if (type && type->tp_clear)
        type->tp_clear(obj);
}

/* PyObject_GenericGetAttrNoDict */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, attr_name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(attr_name));
#endif
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
    PyObject *descr;
    PyTypeObject *tp = Py_TYPE(obj);
    if (unlikely(!PyString_Check(attr_name))) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    assert(!tp->tp_dictoffset);
    descr = _PyType_Lookup(tp, attr_name);
    if (unlikely(!descr)) {
        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
    }
    Py_INCREF(descr);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
    #endif
    {
        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
        if (unlikely(f)) {
            PyObject *res = f(descr, obj, (PyObject *)tp);
            Py_DECREF(descr);
            return res;
        }
    }
    return descr;
}
#endif

/* PyObject_GenericGetAttr */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
}
#endif

/* SetVTable */
static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

/* Import */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* CalculateMetaclass */
static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
    Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
    for (i=0; i < nbases; i++) {
        PyTypeObject *tmptype;
        PyObject *tmp = PyTuple_GET_ITEM(bases, i);
        tmptype = Py_TYPE(tmp);
#if PY_MAJOR_VERSION < 3
        if (tmptype == &PyClass_Type)
            continue;
#endif
        if (!metaclass) {
            metaclass = tmptype;
            continue;
        }
        if (PyType_IsSubtype(metaclass, tmptype))
            continue;
        if (PyType_IsSubtype(tmptype, metaclass)) {
            metaclass = tmptype;
            continue;
        }
        PyErr_SetString(PyExc_TypeError,
                        "metaclass conflict: "
                        "the metaclass of a derived class "
                        "must be a (non-strict) subclass "
                        "of the metaclasses of all its bases");
        return NULL;
    }
    if (!metaclass) {
#if PY_MAJOR_VERSION < 3
        metaclass = &PyClass_Type;
#else
        metaclass = &PyType_Type;
#endif
    }
    Py_INCREF((PyObject*) metaclass);
    return (PyObject*) metaclass;
}

/* Py3ClassCreate */
static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
                                           PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
    PyObject *ns;
    if (metaclass) {
        PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare);
        if (prep) {
            PyObject *pargs = PyTuple_Pack(2, name, bases);
            if (unlikely(!pargs)) {
                Py_DECREF(prep);
                return NULL;
            }
            ns = PyObject_Call(prep, pargs, mkw);
            Py_DECREF(prep);
            Py_DECREF(pargs);
        } else {
            if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
                return NULL;
            PyErr_Clear();
            ns = PyDict_New();
        }
    } else {
        ns = PyDict_New();
    }
    if (unlikely(!ns))
        return NULL;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
    if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
    return ns;
bad:
    Py_DECREF(ns);
    return NULL;
}
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
                                      PyObject *dict, PyObject *mkw,
                                      int calculate_metaclass, int allow_py2_metaclass) {
    PyObject *result, *margs;
    PyObject *owned_metaclass = NULL;
    if (allow_py2_metaclass) {
        owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
        if (owned_metaclass) {
            metaclass = owned_metaclass;
        } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
            PyErr_Clear();
        } else {
            return NULL;
        }
    }
    if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
        metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
        Py_XDECREF(owned_metaclass);
        if (unlikely(!metaclass))
            return NULL;
        owned_metaclass = metaclass;
    }
    margs = PyTuple_Pack(3, name, bases, dict);
    if (unlikely(!margs)) {
        result = NULL;
    } else {
        result = PyObject_Call(metaclass, margs, mkw);
        Py_DECREF(margs);
    }
    Py_XDECREF(owned_metaclass);
    return result;
}

/* CLineInTraceback */
#ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

/* AddTraceback */
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = NULL;
    PyObject *py_funcname = NULL;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_srcfile = NULL;
    py_srcfile = PyString_FromString(filename);
    if (!py_srcfile) goto bad;
    #endif
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        funcname = PyUnicode_AsUTF8(py_funcname);
        if (!funcname) goto bad;
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        if (!py_funcname) goto bad;
        #endif
    }
    #if PY_MAJOR_VERSION < 3
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    #else
    py_code = PyCode_NewEmpty(filename, funcname, py_line);
    #endif
    Py_XDECREF(py_funcname);  // XDECREF since it's only set on Py3 if cline
    return py_code;
bad:
    Py_XDECREF(py_funcname);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_srcfile);
    #endif
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject *ptype, *pvalue, *ptraceback;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
    if (!py_code) {
        __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) {
            /* If the code object creation fails, then we should clear the
               fetched exception references and propagate the new exception */
            Py_XDECREF(ptype);
            Py_XDECREF(pvalue);
            Py_XDECREF(ptraceback);
            goto bad;
        }
        __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        tstate,            /*PyThreadState *tstate,*/
        py_code,           /*PyCodeObject *code,*/
        __pyx_d,    /*PyObject *globals,*/
        0                  /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

/* CIntFromPyVerify */
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* CIntFromPy */
static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const size_t neg_one = (size_t) -1, const_zero = (size_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(size_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (size_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) {
                            return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) {
                            return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 4 * PyLong_SHIFT) {
                            return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (size_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(size_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(size_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) ((((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) ((((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) ((((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(size_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            size_t val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (size_t) -1;
        }
    } else {
        size_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (size_t) -1;
        val = __Pyx_PyInt_As_size_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to size_t");
    return (size_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to size_t");
    return (size_t) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntFromPy */
static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(unsigned int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(unsigned int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (unsigned int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (unsigned int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(unsigned int, digit, digits[0])
                case 2:
                    if (8 * sizeof(unsigned int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) >= 2 * PyLong_SHIFT) {
                            return (unsigned int) (((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(unsigned int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) >= 3 * PyLong_SHIFT) {
                            return (unsigned int) (((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(unsigned int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) >= 4 * PyLong_SHIFT) {
                            return (unsigned int) (((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (unsigned int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(unsigned int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (unsigned int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(unsigned int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(unsigned int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(unsigned int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) {
                            return (unsigned int) (((unsigned int)-1)*(((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(unsigned int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) {
                            return (unsigned int) ((((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) {
                            return (unsigned int) (((unsigned int)-1)*(((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(unsigned int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) {
                            return (unsigned int) ((((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT) {
                            return (unsigned int) (((unsigned int)-1)*(((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(unsigned int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT) {
                            return (unsigned int) ((((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(unsigned int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(unsigned int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(unsigned int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(unsigned int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            unsigned int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (unsigned int) -1;
        }
    } else {
        unsigned int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (unsigned int) -1;
        val = __Pyx_PyInt_As_unsigned_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to unsigned int");
    return (unsigned int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to unsigned int");
    return (unsigned int) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CheckBinaryVersion */
static int __Pyx_check_binary_version(void) {
    char ctversion[5];
    int same=1, i, found_dot;
    const char* rt_from_call = Py_GetVersion();
    PyOS_snprintf(ctversion, 5, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    found_dot = 0;
    for (i = 0; i < 4; i++) {
        if (!ctversion[i]) {
            same = (rt_from_call[i] < '0' || rt_from_call[i] > '9');
            break;
        }
        if (rt_from_call[i] != ctversion[i]) {
            same = 0;
            break;
        }
    }
    if (!same) {
        char rtversion[5] = {'\0'};
        char message[200];
        for (i=0; i<4; ++i) {
            if (rt_from_call[i] == '.') {
                if (found_dot) break;
                found_dot = 1;
            } else if (rt_from_call[i] < '0' || rt_from_call[i] > '9') {
                break;
            }
            rtversion[i] = rt_from_call[i];
        }
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* InitStrings */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        if (PyObject_Hash(*t->p) == -1)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    char* defenc_c;
    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
    if (!defenc) return NULL;
    defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    {
        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
        char* c;
        for (c = defenc_c; c < end; c++) {
            if ((unsigned char) (*c) >= 128) {
                PyUnicode_AsASCIIString(o);
                return NULL;
            }
        }
    }
#endif
    *length = PyBytes_GET_SIZE(defenc);
    return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(PyUnicode_IS_ASCII(o))) {
        *length = PyUnicode_GET_LENGTH(o);
        return PyUnicode_AsUTF8(o);
    } else {
        PyUnicode_AsASCIIString(o);
        return NULL;
    }
#else
    return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
    int retval;
    if (unlikely(!x)) return -1;
    retval = __Pyx_PyObject_IsTrue(x);
    Py_DECREF(x);
    return retval;
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type %.200s).  "
                "The ability to return an instance of a strict subclass of int "
                "is deprecated, and may be removed in a future version of Python.",
                Py_TYPE(result)->tp_name)) {
            Py_DECREF(result);
            return NULL;
        }
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type %.200s)",
                 type_name, type_name, Py_TYPE(result)->tp_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(PyLong_Check(x)))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(b);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
  if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
    return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
#if PY_MAJOR_VERSION < 3
  } else if (likely(PyInt_CheckExact(o))) {
    return PyInt_AS_LONG(o);
#endif
  } else {
    Py_ssize_t ival;
    PyObject *x;
    x = PyNumber_Index(o);
    if (!x) return -1;
    ival = PyInt_AsLong(x);
    Py_DECREF(x);
    return ival;
  }
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
