public void ReadHfsPlusFilesystemTest() { using (Stream stream = File.OpenRead("TestAssets/hfsp.cdr")) using (HfsPlusFileSystem hfs = new HfsPlusFileSystem(stream)) { Assert.True(hfs.FileExists("hello.txt")); using (Stream helloStream = hfs.OpenFile("hello.txt", FileMode.Open, FileAccess.Read)) using (MemoryStream copyStream = new MemoryStream()) { Assert.NotEqual(0, helloStream.Length); helloStream.CopyTo(copyStream); Assert.Equal(helloStream.Length, copyStream.Length); Assert.Equal("Hello, World!\n", Encoding.UTF8.GetString(copyStream.ToArray())); } } }
/// <summary> /// Gets a <see cref="SystemVersion"/> object with additional information about the developer /// disk image. /// </summary> /// <param name="developerDiskImageStream"> /// A <see cref="Stream"/> which represents the developer disk image. /// </param> /// <returns> /// A <see cref="SystemVersion"/> object with additional information about the developer /// disk image. /// </returns> public static (SystemVersion, DateTimeOffset) GetVersionInformation(Stream developerDiskImageStream) { using (var disk = new Disk(developerDiskImageStream, Ownership.None)) { // Find the first (and supposedly, only, HFS partition) var volumes = VolumeManager.GetPhysicalVolumes(disk); if (volumes.Length != 1) { throw new InvalidDataException($"The developer disk should contain exactly one volume"); } using (var volumeStream = volumes[0].Open()) using (var hfs = new HfsPlusFileSystem(volumeStream)) { if (hfs.FileExists(SystemVersionPath)) { using (Stream systemVersionStream = hfs.OpenFile(SystemVersionPath, FileMode.Open, FileAccess.Read)) { var dict = (NSDictionary)PropertyListParser.Parse(systemVersionStream); SystemVersion plist = new SystemVersion(); plist.FromDictionary(dict); if (plist.ProductName != "iPhone OS") { throw new InvalidDataException("The developer disk does not target iOS"); } return(plist, hfs.Root.CreationTimeUtc); } } } throw new InvalidDataException($"The file does not contain any HFS+ parition. Is it a valid developer disk image?"); } }