/// <summary> /// Creates a new file structure. /// </summary> /// <param name="stream">Stream to write the file structure to.</param> /// <param name="fileFormat">File format for the file structure.</param> /// <param name="embedFilePaths">Paths to files to embedd in the file structure.</param> /// <returns>Newly created file structure.</returns> public static FileStructure Create(Stream stream, FileFormat fileFormat, IEnumerable <string> embedFilePaths) { var fs = new FileStructure(); using (var writer = new BinaryWriter(stream, Encoding.UTF8, true)) { fs.WriteType(writer, fileFormat); fs.WriteEmbeddedFiles(writer, embedFilePaths?.ToArray() ?? Array.Empty <string>()); // Remember the data stream offset, which is right after the embedded files have been written. fs.dataStreamOffset = stream.Position; } fs.stream = stream; return(fs); }
/// <summary> /// Creates a new file structure. /// </summary> /// <param name="stream">Stream to write the file structure to.</param> /// <param name="fileFormat">File format for the file structure.</param> /// <param name="embedFilePaths">Paths to files to embedd in the file structure.</param> /// <returns>Newly created file structure.</returns> public static FileStructure Create(Stream stream, FileFormat fileFormat, List <string> embedFilePaths) { FileStructure fs = new FileStructure(); using (NonClosingStreamWrapper wrapper = new NonClosingStreamWrapper(stream)) using (BinaryWriter writer = new BinaryWriter(wrapper)) { fs.WriteType(writer, fileFormat); fs.WriteEmbeddedFiles(writer, embedFilePaths ?? new List <string>()); // Remember the data stream offset, which is right after the embedded files have been written. fs.dataStreamOffset = stream.Position; } fs.stream = stream; return(fs); }