Ejemplo n.º 1
0
        public File(string path, int maxSizeFilePart)
        {
            while (IsFileLocked(path))
            {
                System.Threading.Thread.Sleep(10);
            }
            var file   = System.IO.File.ReadAllBytes(path);
            var file__ = Packaging.EncodeBase64(file);

            //var file = System.IO.File.ReadAllText(path);
            //var file_ = Packaging.Zip(file);
            //var file__ = Packaging.EncodeBase64(file_);

            fileObjects = new System.Collections.Generic.List <FileObject>();

            var count = (uint)System.Math.Ceiling((double)file__.Length / maxSizeFilePart);

            int runner = 0;

            var id_    = System.Guid.NewGuid().ToString();
            var fname_ = System.IO.Path.GetFileName(path);

            for (uint i = 0; i < count; ++i)
            {
                var fileObject = new FileObject()
                {
                    id       = id_,
                    filename = fname_,
                    index    = i,
                    count    = count
                };

                if (i < count - 1)
                {
                    fileObject.content = file__.Substring(runner, maxSizeFilePart);
                    runner            += maxSizeFilePart;
                }
                else
                {
                    fileObject.content = file__.Substring(runner);
                }

                fileObjects.Add(fileObject);
            }
        }
Ejemplo n.º 2
0
        public void writeToFile(string path)
        {
            fileObjects.Sort();

            var file__ = "";

            foreach (var fileObject in fileObjects)
            {
                file__ += fileObject.content;
            }

            //var file_ = Packaging.DecodeBase64(file__);
            //var file = Packaging.Unzip(file_);
            //System.IO.File.WriteAllText(path, file);

            var file = Packaging.DecodeBase64(file__);

            System.IO.File.WriteAllBytes(path, file);
        }