当前位置: 首页>>代码示例>>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;未经允许,请勿转载。