Beispiel #1
0
        public static async Task <FileFormat> GetAsync(Stream stream)
        {
            // Get first 16K
            stream.Seek(0, SeekOrigin.Begin);

            var firstBytes = await FileFormatUtils.ReadBytesAsync(stream, SixteenKilobytes);

            // Get last 16K
            var lastBytes = firstBytes;

            if (stream.Length > SixteenKilobytes)
            {
                var offset = stream.Length - SixteenKilobytes;

                stream.Seek(offset, SeekOrigin.Begin);

                lastBytes = await FileFormatUtils.ReadBytesAsync(stream, SixteenKilobytes);
            }

            // Perform scan
            var job         = new FileFormatScanJob(Scanners, firstBytes, lastBytes, stream);
            var fingerprint = await job.ScanAsync();

            return(fingerprint);
        }
Beispiel #2
0
        public static FileFormat Get(Stream stream)
        {
            // Get first 4K
            stream.Seek(0, SeekOrigin.Begin);

            var firstBytes = FileFormatUtils.ReadBytes(stream, FourKilobytes);

            // Get last 4K
            var lastBytes = firstBytes;

            if (stream.Length > FourKilobytes)
            {
                var offset = stream.Length - FourKilobytes;

                stream.Seek(offset, SeekOrigin.Begin);

                lastBytes = FileFormatUtils.ReadBytes(stream, FourKilobytes);
            }

            // Perform scan
            var job         = new FileFormatScanJob(Scanners, firstBytes, lastBytes, stream);
            var fingerprint = job.Scan();

            return(fingerprint);
        }