コード例 #1
0
ファイル: Decompress.cs プロジェクト: i-e-b/SimpleCompress
        static void WriteFileToAllPaths(IList <string> subPaths, Stream fs, long fileLength, IEnumerable <byte> expectedHash)
        {
            // read source into first file
            var firstPath = subPaths[0];

            PutFolder(firstPath);
            // <data:byte array>
            CopyLength(fs, firstPath, fileLength, expectedHash);
            if (subPaths.Count == 1)
            {
                return;
            }

            // copy first file into all other locations
            var srcInfo = new PathInfo(firstPath);

            for (int i = 1; i < subPaths.Count; i++)
            {
                var thisPath = subPaths[i];
                PutFolder(thisPath);
                if (!NativeIO.CopyFile(srcInfo, new PathInfo(thisPath)))
                {
                    throw new Exception("Failed to write " + thisPath);
                }
            }
        }
コード例 #2
0
        public static void files_can_be_created_and_written_and_read_and_copied_in_very_long_paths()
        {
            // Create a >255 length path
            const string path = TempRoot + "\\QIO\\Pseudopseudohypoparathyroidism\\Pneumonoultramicroscopicsilicovolcanoconiosis\\Floccinaucinihilipilification\\Antidisestablishmentarianism\\Honorificabilitudinitatibus\\Donau­dampf­schiffahrts­elektrizitäten­haupt­betriebs­werk­bau­unter­beamten­gesellschaft";

            NativeIO.CreateDirectory(new PathInfo(path), recursive: true);

            var sampleData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var srcFile    = new PathInfo(path + "\\example.file.txt");
            var dstFile    = new PathInfo(path + "\\example.copy.txt");

            // write a file
            using (var fs = NativeIO.OpenFileStream(srcFile, FileAccess.Write, FileMode.Create, FileShare.None)) {
                fs.Write(sampleData, 4, 4);
                fs.Write(sampleData, 0, 4);
                fs.Flush();
            }


            // copy the file elsewhere
            Assert.True(NativeIO.Exists(srcFile), "Source file can't be found (didn't write correctly?)");
            Assert.False(NativeIO.SymbolicLink.IsSymLink(srcFile), "File was a sym-link");
            Assert.True(NativeIO.CopyFile(srcFile, dstFile), "Failed to copy file");
            Assert.True(NativeIO.Exists(dstFile), "Target file can't be found");

            // Check the contents
            using (var fs = NativeIO.OpenFileStream(srcFile, FileAccess.Read))
            {
                var buf    = new byte[8];
                var length = fs.Read(buf, 0, 8);
                Assert.That(length, Is.EqualTo(8));
                Assert.That(buf, Is.EquivalentTo(new byte[] { 5, 6, 7, 8, 1, 2, 3, 4 }));
            }

            // cleanup
            NativeIO.DeleteDirectory(new DirectoryDetail(TempRoot + "\\QIO"), recursive: true);
        }