#!/usr/bin/env python3
"""

See EOF for license/metadata/notes as applicable
"""

##-- builtin imports
from __future__ import annotations

# import abc
import datetime
import enum
import functools as ftz
import itertools as itz
import logging as logmod
import pathlib as pl
import re
import time
import types
import weakref
# from copy import deepcopy
# from dataclasses import InitVar, dataclass, field
from typing import (TYPE_CHECKING, Any, Callable, ClassVar, Final, Generic,
                    Iterable, Iterator, Mapping, Match, MutableMapping,
                    Protocol, Sequence, Tuple, TypeAlias, TypeGuard, TypeVar,
                    cast, final, overload, runtime_checkable, Generator)
from uuid import UUID, uuid1

##-- end builtin imports

##-- lib imports
import more_itertools as mitz
##-- end lib imports

##-- logging
logging = logmod.getLogger(__name__)
##-- end logging

import mmap

class JGDVMemMap:
    """
      A utility wrapper to easily make memory mapped files from a path,
      and use them as in a context manager
    """

    def __init__(self, path:pl.Path):
        self._path = path
        self._file = None
        self._mmap = None

    def __enter__(self):
        if self._mmap:
            return

        self._file = open(self._path, "r+b")
        self._mmap = mmap.mmap(self._file.fileno(), 0)

    def __exit__(self, exc_type, exc_value, exc_traceback) -> bool:
        if self._mmap:
            self._mmap.close()
        if self._file:
            self._file.close()

        return

    def seek(self, x):
        raise NotImplementedError()

    def read(self):
        raise NotImplementedError()
