public static IIronLeveldb BuildFromSingleTable(Stream stream, IronLeveldbOptions options)
        {
            var table = new Table(new StreamContentReader(stream), options.BlockCache,
                                  new InternalKeyComparer(options.Comparer), options.SnappyDecompressor);

            return(new IronLeveldbStub(options, table, stream.Dispose));
        }
 public IronLeveldbStub(IronLeveldbOptions options,
                        ISeekable <InternalKey, InternalIByteArrayKeyValuePair> dataProvider, Action onDispose = null)
 {
     _dataProvider = dataProvider;
     _onDispose    = onDispose;
     _comparer     = options?.Comparer ?? LeveldbDefaultKeyComparer.Comparer;
 }
        public static IIronLeveldb Build(this IIronLeveldbStorge storge, IronLeveldbOptions options)
        {
            var manifestContent = storge.GetCurrentDescriptorContent();

            // TODO base version
            var b = new Version.Builder(storge, options, null);

            using (var manifestStream = manifestContent.AsStream())
            {
                foreach (var stream in new RecoverLogRecordsStream(manifestStream))
                {
                    var versionEdit = VersionEdit.DecodeFrom(stream);

                    b.With(versionEdit);
                }
            }

            var current = b.Build();

            return(new IronLeveldbStub(options, current, () =>
            {
                var es = new List <Exception>();
                try
                {
                    storge.Dispose();
                }
                catch (Exception e)
                {
                    es.Add(e);
                }

                try
                {
                    current.Dispose();
                }
                catch (Exception e)
                {
                    es.Add(e);
                }

                if (es.Count > 1)
                {
                    throw new AggregateException(es);
                }

                if (es.Count == 1)
                {
                    throw es.First();
                }
            }));
        }
 public static IIronLeveldb BuildFromPath(string path, IronLeveldbOptions options)
 {
     return(Build(new ReadonlyFileSystemStorage(path), options));
 }