Exemple #1
0
        public string StoreData(byte[] data, string extension = null)
        {
            var hasher = new SHA256Managed();

            hasher.Initialize();

            string hash = null;

            using (hasher)
            {
                hash = HexTools.ByteArrayToHexString(hasher.ComputeHash(data));

                var targetPath = BuildPath(hash, extension);
                if (_storage.Exists(targetPath))
                {
                    return(null);
                }

                var directory = Path.GetDirectoryName(targetPath);
                _storage.CreateFolder(directory);

                var file = _storage.Open(targetPath);
                using (file)
                {
                    file.Write(data, 0, data.Length);
                }
            }

            return(hash);
        }