         let data = Data("Hello, World!\n".utf8)
         let entry = TarEntry(info: info, data: data)
 
-        let tempFileUrl = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString, isDirectory: false)
-        try "".write(to: tempFileUrl, atomically: true, encoding: .utf8)
-        let handle = try FileHandle(forWritingTo: tempFileUrl)
-        var writer = TarWriter(fileHandle: handle)
-        try writer.append(entry)
-        try writer.finalize()
-        try handle.closeCompat()
-        let containerData = try Data(contentsOf: tempFileUrl)
+        let containerData = try TarWriterTests.generateContainerData([entry])
         XCTAssertEqual(try TarContainer.formatOf(container: containerData), .pax)
         let newEntries = try TarContainer.open(container: containerData)
 

        XCTAssertEqual(newEntries[0].data, data)
    }

}


class TarWriterTests: XCTestCase {

    private static let tempDir = URL(fileURLWithPath: NSTemporaryDirectory())
        .appendingPathComponent("TestSWCompression-" + UUID().uuidString, isDirectory: true)

    class override func setUp() {
        do {
            try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: nil)
        } catch let error {
            fatalError("TarWriterTests.setUp(): unable to create temporary directory: \(error)")
        }
    }

    class override func tearDown() {
        do {
            try FileManager.default.removeItem(at: tempDir)
        } catch let error {
            fatalError("TarWriterTests.tearDown(): unable to remove temporary directory: \(error)")
        }
    }

    private static func generateContainerData(_ entries: [TarEntry], format: TarContainer.Format = .pax) throws -> Data {
        let tempFileUrl = tempDir.appendingPathComponent(UUID().uuidString, isDirectory: false)
        try "".write(to: tempFileUrl, atomically: true, encoding: .utf8)
        let handle = try FileHandle(forWritingTo: tempFileUrl)
        var writer = TarWriter(fileHandle: handle, format: format)
        for entry in entries {
            try writer.append(entry)
        }
        try writer.finalize()
        try handle.closeCompat()
        return try Data(contentsOf: tempFileUrl)
    }

    func test1() throws {
        var info = TarEntryInfo(name: "file.txt", type: .regular)
        info.ownerUserName = "timofeysolomko"
        info.ownerGroupName = "staff"
