Ejemplo n.º 1
0
 /// <summary>
 /// Using to decompress (parse bytes to Metadata type)
 /// </summary>
 internal Metadata(byte[] bytes, int metadataSize)
 {
     try
     {
         _magicWordBytes = Encoding.UTF8.GetBytes(_magicWord);
         var byteList = bytes.ToList();
         int offset   = 0;
         if (Encoding.UTF8.GetString(byteList.GetRange(offset, _magicWordBytes.Length).ToArray()) != _magicWord)
         {
             throw new WrongSourceFileException("File header has been corrupted or file has not been compressed by this compressor.");
         }
         offset       += _magicWordBytes.Length;
         MetadataSize  = metadataSize;
         offset       += sizeof(int);
         FileExtension = Encoding.UTF8.GetString(byteList.GetRange(offset, 8).ToArray()).Replace("\0", "");
         offset       += 8;
         while (offset < byteList.Count)
         {
             var compressedOffset = BitConverter.ToInt64(byteList.GetRange(offset, sizeof(long)).ToArray(), 0);
             offset += sizeof(long);
             var decompressedOffset = BitConverter.ToInt64(byteList.GetRange(offset, sizeof(long)).ToArray(), 0);
             offset += sizeof(long);
             var chunk = new ChunkMetadata(compressedOffset, decompressedOffset);
             ChunkList.Add(chunk);
         }
     }
     catch (WrongSourceFileException ex)
     {
         throw new WrongSourceFileException(ex.Message);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Using to compress
 /// </summary>
 internal Metadata(string source, long sourceSize)
 {
     _magicWordBytes = Encoding.UTF8.GetBytes(_magicWord);
     FileExtension   = Helper.GetFileExtension(source);
     MetadataSize    = _magicWordBytes.Length
                       + sizeof(int)
                       + 8
                       + (int)Math.Ceiling((double)sourceSize / Settings.ChunkSizeBytes) * ChunkMetadata.SizeOf();
 }