Exemplo n.º 1
0
        private long ReadOffsets(string currentFileName)
        {
            long position;

            if (streamSource.Exists(offsetsPath) == false)
            {
                return(0);
            }
            using (var offsets = streamSource.OpenRead(offsetsPath))
                using (var reader = new BinaryReader(offsets))
                {
                    var fileName = reader.ReadString();
                    if (fileName != currentFileName)
                    {
                        // wrong file, skipping
                        streamSource.DeleteOnClose(offsetsPath);
                        return(0);
                    }
                    position = reader.ReadInt64();

                    while (true)
                    {
                        string key;
                        try
                        {
                            key = reader.ReadString();
                        }
                        catch (EndOfStreamException)
                        {
                            break;
                        }
                        var pos   = reader.ReadInt64();
                        var count = reader.ReadInt32();

                        idToPos[key] = new StreamInformation
                        {
                            LastPosition = pos,
                            StreamLength = count
                        };
                    }
                }

            return(position);
        }