File size: 1,606 Bytes
fab29d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) Dr. Dirk Lellinger. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Text;
using SlobViewer.Common;

namespace SlobViewer.Slob
{
  /// <summary>
  /// Part of a <see cref="SlobDictionaryInMemory"/>. A <see cref="StoreItemInMemory"/> holds multiple dictionary values. After reading the SLOB file,
  /// the content is stored in compressed form. If the contents is accessed, it is decompressed.
  /// </summary>
  public class StoreItemInMemory : StoreItemBase
  {

    /// <summary>
    /// Initializes a new instance of the <see cref="StoreItemInMemory"/> class.
    /// </summary>
    /// <param name="contentIds">The array of content IDs.</param>
    /// <param name="compressedContent">Compressed content as retrieved from the SLOB file.</param>
    public StoreItemInMemory(byte[] contentIds, byte[] compressedContent)
    {
      _contentIds = contentIds;
      _compressedContent = compressedContent;
    }

    /// <summary>
    /// Get the content item with index <paramref name="idx"/>.
    /// </summary>
    /// <param name="idx">The index.</param>
    /// <returns>A tuple, consisting of the content and content id at index <paramref name="idx"/>.</returns>
    public (string Content, int ContentId) GetAt(int idx, Encoding encoding, string compression, byte[] buffer)
    {
      if (null != _compressedContent)
      {
        DecompressContent(encoding, compression, buffer);

        _compressedContent = null;
      }

      return (_content[idx], _contentIds[idx]);
    }


  }
}