Exemple #1
0
    def __init__(self, path, serializer=None):
        if serializer is None:
            serializer = UnicodeSerializer()  # by default, just write to file as utf-8 encoded strings

        self._path = path
        self._ser = serializer

        # open or create the corresponding file
        self._f_read = open_or_create(path, 'r')  # for reading only
        self._f_write = open_or_create(path, 'a')  # for appending. Stream positioned at end of file.

        # create metadata
        self._offsets = FileSequenceOffsets(self)  # note: this must come before metadata
        self._meta = FileSequenceMetaData(self)
Exemple #2
0
 def __init__(self, path):
     self._path = path
     self._f = open_or_create(self._path, 'r+')
     s = self._f.read()
     if len(s) == 0:
         self._d = {}
     else:
         self._d = json.loads(s)
Exemple #3
0
    def __init__(self, path, serializer=None):
        if serializer is None:
            serializer = UnicodeSerializer(
            )  # by default, just write to file as utf-8 encoded strings

        self._path = path
        self._ser = serializer

        # open or create the corresponding file
        self._f_read = open_or_create(path, 'r')  # for reading only
        self._f_write = open_or_create(
            path, 'a')  # for appending. Stream positioned at end of file.

        # create metadata
        self._offsets = FileSequenceOffsets(
            self)  # note: this must come before metadata
        self._meta = FileSequenceMetaData(self)
Exemple #4
0
 def __init__(self, path):
     self._path = path
     self._f = open_or_create(self._path, 'r+')
     s = self._f.read()
     if len(s) == 0:
         self._d = {}
     else:
         self._d = json.loads(s)
Exemple #5
0
    def __init__(self, file_seq):
        offsets_path = file_seq.path + '.offsets'
        file_existed = os.path.isfile(offsets_path)  # check if file already existed
        self._f_write = open_or_create(offsets_path, 'a')  # open for appending only

        if file_existed:
            # load offsets from file into memory
            with open(offsets_path, 'r') as f:
                self._offsets = [int(line) for line in f]  # int cast strips newline automatically
        else:
            # build offsets (in-memory and on-file)
            self._offsets = []
            current_offset = 0
            for line in file_seq.iter_raw_lines():
                self.append(current_offset)
                current_offset += len(line)

        self._offsets_path = offsets_path
Exemple #6
0
    def __init__(self, file_seq):
        offsets_path = file_seq.path + '.offsets'
        file_existed = os.path.isfile(
            offsets_path)  # check if file already existed
        self._f_write = open_or_create(offsets_path,
                                       'a')  # open for appending only

        if file_existed:
            # load offsets from file into memory
            with open(offsets_path, 'r') as f:
                self._offsets = [int(line) for line in f
                                 ]  # int cast strips newline automatically
        else:
            # build offsets (in-memory and on-file)
            self._offsets = []
            current_offset = 0
            for line in file_seq.iter_raw_lines():
                self.append(current_offset)
                current_offset += len(line)

        self._offsets_path = offsets_path