private void WriteEndContainer(BionMarker container) { Write(container); // End Index is bytes written *after* end marker, so seek will find the next thing _containerIndex?.End(_writer.BytesWritten); }
public void RewriteOptimized(BufferedWriter writer, string containerIndexPath = null, string searchIndexPath = null) { int[] map = _compressor.OptimizeIndex(); using (BufferedReader inner = BufferedReader.FromArray(_reader.Buffer, 0, 0)) using (ContainerIndex containerIndex = (containerIndexPath == null ? null : ContainerIndex.OpenWrite(containerIndexPath))) using (SearchIndexWriter indexWriter = (searchIndexPath == null ? null : new SearchIndexWriter(searchIndexPath, map.Length, 128 * 1024))) { long last = 0; while (this.Read()) { int length = (int)(this.BytesRead - last); writer.EnsureSpace(length); if (LengthLookup[(byte)_currentMarker] >= 0) { // Everything but compressed text: write bytes out Buffer.BlockCopy(_reader.Buffer, _reader.Index - length, writer.Buffer, writer.Index, length); writer.Index += length; } else { writer.Buffer[writer.Index++] = (byte)_currentMarker; // Compressed Test: Rewrite the text segment inner.ReadSlice(_reader.Buffer, _reader.Index - _currentLength, _reader.Index - 1); _compressor.RewriteOptimized(map, inner, writer, indexWriter); writer.Buffer[writer.Index++] = (byte)BionMarker.EndValue; } if ((byte)_currentMarker >= (byte)BionMarker.EndArray) { if ((byte)_currentMarker >= (byte)BionMarker.StartArray) { containerIndex?.Start(writer.BytesWritten - 1); } else { containerIndex?.End(writer.BytesWritten); } } last = this.BytesRead; } } }