Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string url = @"http://speed.myzone.cn/WindowsXP_SP2.exe";
            HttpFileSplit split = new HttpFileSplit();
            long blockSize = 1024 * 3;
            if (split.TryToSplit(url, blockSize))
            {
                Console.WriteLine("url:" + url);
                Console.WriteLine("fileSize_:" + split.fileSize_);
                Console.WriteLine("blockCount_:" + split.blockCount_);
                Console.WriteLine("lastBlockSize_:" + split.lastBlockSize_);

                Console.ReadKey();
                byte[] data = HttpDownloadRange.Download(url, 3 * split.blockSize_, 4 * split.blockSize_ - 1);
                if (data != null && data.Length == split.blockSize_)
                {
                    Console.WriteLine("HttpDownloadRange ok");
                }
            }
            Console.ReadKey();
        }
Exemplo n.º 2
0
Arquivo: Program.cs Projeto: sgww/cozy
        static void Main(string[] args)
        {
            string        url       = @"http://speed.myzone.cn/WindowsXP_SP2.exe";
            HttpFileSplit split     = new HttpFileSplit();
            long          blockSize = 1024 * 3;

            if (split.TryToSplit(url, blockSize))
            {
                Console.WriteLine("url:" + url);
                Console.WriteLine("fileSize_:" + split.fileSize_);
                Console.WriteLine("blockCount_:" + split.blockCount_);
                Console.WriteLine("lastBlockSize_:" + split.lastBlockSize_);

                Console.ReadKey();
                byte[] data = HttpDownloadRange.Download(url, 3 * split.blockSize_, 4 * split.blockSize_ - 1);
                if (data != null && data.Length == split.blockSize_)
                {
                    Console.WriteLine("HttpDownloadRange ok");
                }
            }
            Console.ReadKey();
        }
Exemplo n.º 3
0
 public bool InitTask()
 {
     split_ = new HttpFileSplit();
     if (split_.TryToSplit(RemotePath, BlockSize))
     {
         if (!CreateCacheFile())
         {
             return(false);
         }
         finishCount   = 0;
         taskState_    = new byte[split_.blockCount_];
         subTaskQueue_ = new Queue <DownloadSubTask>();
         lock (subTaskQueue_)
         {
             for (int i = 0; i < split_.blockCount_ - 1; ++i)
             {
                 subTaskQueue_.Enqueue(new DownloadSubTask()
                 {
                     Id         = i,
                     RemotePath = RemotePath,
                     from       = split_.blockSize_ * i,
                     to         = split_.blockSize_ * (i + 1) - 1,
                 });
                 taskState_[i] = 0;
             }
             subTaskQueue_.Enqueue(new DownloadSubTask()
             {
                 Id         = (int)split_.blockCount_ - 1,
                 RemotePath = RemotePath,
                 from       = split_.blockSize_ * (split_.blockCount_ - 1),
                 to         = split_.fileSize_ - 1,
             });
             taskState_[split_.blockCount_ - 1] = 0;
         }
         return(true);
     }
     return(false);
 }