當前位置: 首頁>>代碼示例>>C#>>正文


C# Chunk.AddLast方法代碼示例

本文整理匯總了C#中Chunk.AddLast方法的典型用法代碼示例。如果您正苦於以下問題:C# Chunk.AddLast方法的具體用法?C# Chunk.AddLast怎麽用?C# Chunk.AddLast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Chunk的用法示例。


在下文中一共展示了Chunk.AddLast方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: processTask

 private void processTask(BackupTask task)
 {
     Logger.Debug("StorageThread:processTask:BackupTask");
     //generate list of files
     LinkedList<FileInChunk> allFiles = new LinkedList<FileInChunk>();
     recursivelyFillFileQueue(ref allFiles, task.Path, "");
     int chunkID = 0;
     while (true)
     { //while need more chunks
         Logger.Debug2("StorageThread:processTask outer loop");
         if (allFiles.Count() == 0) break;
         string oFilename = task.TempPath + '\\' + guid + '_' + task.BackupID + '_' + chunkID + ".tgz";
         TarOutputStream tarOutputStream = newTarOutputStream(oFilename);
         Chunk chunk = new Chunk(task.BackupID, chunkID, task.Path, oFilename);
         long size = 0;
         string relPath, fullPath;
         while (true)
         { //while need more files in chunk
             //Logger.Debug2("StorageThread:processTask inner loop");
             if (allFiles.Count() == 0)
             {
                 tarOutputStream.Close();
                 break;
             }
             FileInChunk fileInChunk = allFiles.First();
             relPath = fileInChunk.path;
             fullPath = task.Path + '\\' + relPath;
             if (Directory.Exists(fullPath))
             {
                 //Logger.Debug2("StorageThread:processTask inner loop if 1");
                 TarEntry entry2 = TarEntry.CreateTarEntry(relPath);
                 //entry2.Name = relPath;
                 entry2.TarHeader.TypeFlag = TarHeader.LF_DIR;
                 tarOutputStream.PutNextEntry(entry2);
                 chunk.AddLast(fileInChunk);
                 size += 512;
                 allFiles.RemoveFirst();
                 continue;
             }
             Stream inputStream = File.OpenRead(fullPath);
             long s = inputStream.Length;
             long toWrite = s;
             //add file header size to chunk size
             size += 512;
             TarEntry entry = TarEntry.CreateTarEntry(relPath);
             if (size + s < CHUNK_SIZE)
             {
                 //Logger.Debug2("StorageThread:processTask inner loop if 2");
                 entry.Size = s;
                 tarOutputStream.PutNextEntry(entry);
                 byte[] buffer = new byte[32 * 1024];
                 int totalRead = 0;
                 while (true)
                 {
                     int numRead = inputStream.Read(buffer, 0, buffer.Length);
                     if (numRead <= 0)
                     {
                         break;
                     }
                     totalRead += numRead;
                     tarOutputStream.Write(buffer, 0, numRead);
                 }
                 tarOutputStream.CloseEntry();
                 chunk.AddLast(fileInChunk);
                 allFiles.RemoveFirst();
                 size += s;
                 //if size is not a multiple of 512, round it up to next multiple of 512
                 if (size % 512 != 0)
                 {
                     size += 512 - (size % 512);
                 }
             }
             else
             { //file is too big to fit in chunk in entirety
                 //Logger.Debug2("StorageThread:processTask inner loop else 2");
                 long totalFileRead = 0;
                 int partLength = CHUNK_SIZE - (int)size;
                 createSplitFileInChunks(ref allFiles, partLength, s);
                 fileInChunk = allFiles.First();
                 entry.Size = partLength;
                 tarOutputStream.PutNextEntry(entry);
                 byte[] buffer = new byte[32 * 1024];
                 while (true)
                 { //while we have more chunks from this file to write
                     //Logger.Debug2("StorageThread:processTask inner-inner loop");
                     while (true)
                     {
                         int numRead = inputStream.Read(buffer, 0, Math.Min(buffer.Length, partLength));
                         if (numRead <= 0)
                         {
                             break;
                         }
                         partLength -= numRead;
                         size += numRead;
                         totalFileRead += numRead;
                         tarOutputStream.Write(buffer, 0, numRead);
                     }
                     tarOutputStream.CloseEntry();
                     partLength = CHUNK_SIZE - 512;
                     chunk.AddLast(fileInChunk);
//.........這裏部分代碼省略.........
開發者ID:411blue,項目名稱:echo-backup,代碼行數:101,代碼來源:StorageThread.cs


注:本文中的Chunk.AddLast方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。