Ejemplo n.º 1
0
        public FileParseResult Read(string fileName)
        {
            FileParseResult result = new FileParseResult();

            using (var reader = new BinaryReader(File.OpenRead(fileName)))
            {
                RaeadHeader(reader);
                result.Hash      = ReadHash(reader, hashSize);
                result.Frequency = ReadFrequency(reader, frequencySize);
                result.Distances = ReadDistances(reader, distancesSize);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public string WriteToFile(string fileName, FileParseResult result, byte[] hash, string output, Features features)
        {
            using (Stream stream = new FileStream(output, FileMode.Create))
            {
                using (BinaryWriter bw = new BinaryWriter(stream))
                {
                    WriteHeader(bw, result, (int)features);
                    WriteHash(bw, result.Hash);
                    WriteFrequency(bw, result.Frequency);
                    WriteDistances(bw, result.Distances);
                    bw.Close();
                }
                stream.Close();
            }

            return(output);
        }
Ejemplo n.º 3
0
        public static void WriteHeader(BinaryWriter bw, FileParseResult result, int features)
        {
            int hashOffset = 7 * 4 + 4 * 10;

            int hashSize = result.Hash.Count * 8 + result.Hash.Sum(h => Encoding.UTF8.GetBytes(h.Value).Length);

            int frequencyOffset = hashOffset + hashSize + 4 * 10;

            int frequencySize = result.Frequency.Count * 4 + result.Frequency.Count * 8;

            int distancesOffset = frequencyOffset + frequencySize + 4 * 10;

            int distancesSize = result.Distances.Sum(h => h.Value.Count) + result.Distances.Count * 8;

            bw.Write(hashOffset);
            bw.Write(hashSize);
            bw.Write(frequencyOffset);
            bw.Write(frequencySize);
            bw.Write(distancesOffset);
            bw.Write(distancesSize);
            bw.Write(features);
        }