/// <summary> /// /// </summary> /// <param name="containerFilePath"></param> /// <param name="loadContent"></param> /// <param name="token"></param> /// <returns></returns> public IContainerFile ReadFile(String containerFilePath, bool loadContent, CancellationToken token) { if (!File.Exists(containerFilePath)) { throw new ArgumentException("A file with the specified path doesn't exist.", "containerFilePath"); } var longestMagic = KnownContainerTypes.Max(x => x.MagicBytes.Length); byte[] magicBuffer = new byte[longestMagic]; using (Stream source = File.OpenRead(containerFilePath)) { source.Read(magicBuffer, 0, magicBuffer.Length); } var containerType = ResolveFileType(magicBuffer); var readFunc = ReadFileFuncs[containerType]; var containerFile = readFunc(containerFilePath, loadContent, token); return(containerFile); }
/// <summary> /// /// </summary> /// <param name="rawContainerFile"></param> /// <param name="loadContent"></param> /// <param name="token"></param> /// <returns></returns> public IContainerFile ReadRaw(byte[] rawContainerFile, bool loadContent, CancellationToken token) { if (rawContainerFile == null) { throw new ArgumentNullException("rawContainerFile"); } var longestMagic = KnownContainerTypes.Max(x => x.MagicBytes.Length); byte[] magicBuffer = new byte[longestMagic]; using (Stream source = new MemoryStream(rawContainerFile)) { source.Read(magicBuffer, 0, magicBuffer.Length); } var containerType = ResolveFileType(magicBuffer); //Może zwrócić unknown, obsłużyć var readFunc = ReadRawFuncs[containerType]; var containerFile = readFunc(rawContainerFile, loadContent, token); return(containerFile); }