Example #1
0
        /// <summary>
        /// Retrieve a read-only stream over an object that has been stored.
        /// </summary>
        /// <param name="key">The object key.</param>
        /// <param name="callbacks">CallbackMethods object containing callback methods.</param>
        /// <returns>Read-only stream.</returns>
        public DedupeStream GetStream(string key, DedupeCallbacks callbacks)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (callbacks == null)
            {
                throw new ArgumentNullException(nameof(callbacks));
            }
            if (callbacks.ReadChunk == null)
            {
                throw new ArgumentException("ReadChunk callback must be specified.");
            }
            key = DedupeCommon.SanitizeString(key);

            DedupeObject md = GetMetadata(key);

            if (md == null)
            {
                throw new KeyNotFoundException("Object key '" + key + "' not found.");
            }

            return(new DedupeStream(md, _Database, callbacks));
        }
Example #2
0
        /// <summary>
        /// Retrieve an object from the deduplication index.
        /// This method will use the callbacks supplied in the method signature.
        /// </summary>
        /// <param name="key">The object key.</param>
        /// <param name="callbacks">CallbackMethods object containing callback methods.</param>
        /// <returns>Object data.</returns>
        public DedupeObject Get(string key, DedupeCallbacks callbacks)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (callbacks == null)
            {
                throw new ArgumentNullException(nameof(callbacks));
            }
            if (callbacks.ReadChunk == null)
            {
                throw new ArgumentException("ReadChunk callback must be specified.");
            }
            key = DedupeCommon.SanitizeString(key);

            DedupeObject md = _Database.GetObjectMetadata(key);

            if (md == null)
            {
                throw new KeyNotFoundException("Object key '" + key + "' not found.");
            }
            if (md.Chunks == null || md.Chunks.Count < 1)
            {
                throw new IOException("No chunks returned for object key '" + key + "'.");
            }

            MemoryStream stream        = new MemoryStream();
            long         contentLength = 0;

            foreach (DedupeObjectMap curr in md.ObjectMap)
            {
                byte[] chunkData = callbacks.ReadChunk(curr.ChunkKey);
                if (chunkData == null || chunkData.Length < 1)
                {
                    throw new IOException("Unable to read chunk '" + curr.ChunkKey + "'.");
                }

                stream.Write(chunkData, 0, chunkData.Length);
                contentLength += chunkData.Length;
            }

            if (contentLength > 0)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            md.DataStream = stream;
            return(md);
        }
Example #3
0
        /// <summary>
        /// Retrieve an object from the deduplication index.
        /// </summary>
        /// <param name="key">The object key.</param>
        /// <param name="data">Object data.</param>
        /// <returns>True if successful.</returns>
        public bool TryGet(string key, out DedupeObject data)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            data = null;

            try
            {
                data = Get(key, Callbacks);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #4
0
        internal DedupeStream(DedupeObject md, DbProvider db, DedupeCallbacks callbacks)
        {
            if (md == null)
            {
                throw new ArgumentNullException(nameof(md));
            }
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }
            if (callbacks == null)
            {
                throw new ArgumentNullException(nameof(callbacks));
            }

            _Metadata  = md;
            _Database  = db;
            _Callbacks = callbacks;
        }