Пример #1
0
        private const int BufferSize = 2048;//NOTE: set to 2048 to fit in minimum tcp window

        public static Stream IronReadStream(this IDataStore store, TempStream tempStream, string domain, string path, int tryCount)
        {
            var ms = tempStream.Create();

            IronReadToStream(store, domain, path, tryCount, ms);
            ms.Seek(0, SeekOrigin.Begin);
            return(ms);
        }
Пример #2
0
        ///<summary>
        /// Copy from one module to another. Can copy from s3 to disk and vice versa
        ///</summary>
        ///<param name="srcStore"></param>
        ///<param name="srcDomain"></param>
        ///<param name="srcFilename"></param>
        ///<param name="dstStore"></param>
        ///<param name="dstDomain"></param>
        ///<param name="dstFilename"></param>
        ///<returns></returns>
        ///<exception cref="ArgumentNullException"></exception>
        public static Uri CrossCopy(IDataStore srcStore, string srcDomain, string srcFilename, IDataStore dstStore,
                                    string dstDomain, string dstFilename)
        {
            if (srcStore == null)
            {
                throw new ArgumentNullException("srcStore");
            }
            if (srcDomain == null)
            {
                throw new ArgumentNullException("srcDomain");
            }
            if (srcFilename == null)
            {
                throw new ArgumentNullException("srcFilename");
            }
            if (dstStore == null)
            {
                throw new ArgumentNullException("dstStore");
            }
            if (dstDomain == null)
            {
                throw new ArgumentNullException("dstDomain");
            }
            if (dstFilename == null)
            {
                throw new ArgumentNullException("dstFilename");
            }
            //Read contents
            using (Stream srcStream = srcStore.GetReadStream(srcDomain, srcFilename))
            {
                using (var memoryStream = TempStream.Create())
                {
                    //Copy
                    var buffer = new byte[4096];
                    int readed;
                    while ((readed = srcStream.Read(buffer, 0, 4096)) != 0)
                    {
                        memoryStream.Write(buffer, 0, readed);
                    }

                    memoryStream.Position = 0;
                    return(dstStore.Save(dstDomain, dstFilename, memoryStream));
                }
            }
        }
        private bool GetStream(Stream stream, out Stream memstream)
        {
            memstream = TempStream.Create();
            var       total = 0;
            int       readed;
            const int portion = 2048;
            var       buffer  = new byte[portion];

            while ((readed = stream.Read(buffer, 0, portion)) > 0)
            {
                memstream.Write(buffer, 0, readed);
                total += readed;
                if (total >= chunksize)
                {
                    break;
                }
            }

            return(total > 0);
        }