Create a TAR archive, using a list of type string, containing an XML #761
Unanswered
rzamurianos
asked this question in
General
Replies: 1 comment
-
I don't see anything that would suggest it shouldn't work. Are you sure your list is not empty? I made this PoC from your code snippet:using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
using ICSharpCode.SharpZipLib.Tar;
var res = GET_FileTAR_With_List(new List<string> {
"This is a content",
"I am also a content",
"Me three"
}, "");
var len = File.WriteAllBytes("output.tar", res);
Console.WriteLine($"Wrote {len} bytes(s)!");
byte[] GET_FileTAR_With_List(List<string> lstInvoiceXML, string Language)
{
byte[] byteArray = null;
try
{
string stringXML = "";
int i = 0;
MemoryStream outputMemStream = new MemoryStream();
TarOutputStream tarOut = new TarOutputStream(outputMemStream);
foreach (var eInvoiceXML in lstInvoiceXML)
{
i += 1;
MemoryStream msFormXml = new MemoryStream(Encoding.UTF8.GetBytes(eInvoiceXML.ToString()));
TarEntry entry = TarEntry.CreateTarEntry("File" + i + ".XML");
entry.Size = msFormXml.Length;
tarOut.PutNextEntry(entry);
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(msFormXml, tarOut, new byte[4096]);
tarOut.CloseEntry();
msFormXml.Close();
}
tarOut.Close();
byteArray = outputMemStream.ToArray();
return byteArray;
}
catch (Exception ex)
{
RecordLog(ex.Message, "GenerarFacturaVentaXMLPorPaquete", "BLSALDServiceInvoicePackage", "ES");
return byteArray;
}
}
void RecordLog(string msg, string g1, string g2, string g3) {
Console.WriteLine($"[{g1}][{g2}][{g3}] {msg}");
} It produced the following file:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I have a list of type string, each of these strings has an XML format. Each string in the list is an XML file. The goal is to create a TAR file that contains all the strings.
I have this code:
The error message when decompressing is: "There are no files in the TAR".
Any ideas, what am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions