The title says it all:
- I read in tar.gz archive for example
- split file into byte array
- Convert these bytes to a Base64 string
- Convert this Base64 string back to byte array
- Write these bytes back to the new tar.gz file.
I can confirm that both files are the same size (the method below returns true), but I can no longer extract the version to copy.
Did I miss something?
Boolean MyMethod(){ using (StreamReader sr = new StreamReader("C:\...\file.tar.gz")) { String AsString = sr.ReadToEnd(); byte[] AsBytes = new byte[AsString.Length]; Buffer.BlockCopy(AsString.ToCharArray(), 0, AsBytes, 0, AsBytes.Length); String AsBase64String = Convert.ToBase64String(AsBytes); byte[] tempBytes = Convert.FromBase64String(AsBase64String); File.WriteAllBytes(@"C:\...\file_copy.tar.gz", tempBytes); } FileInfo orig = new FileInfo("C:\...\file.tar.gz"); FileInfo copy = new FileInfo("C:\...\file_copy.tar.gz");
EDIT: The working example is much simpler (thanks @TS):
Boolean MyMethod(){ byte[] AsBytes = File.ReadAllBytes(@"C:\...\file.tar.gz"); String AsBase64String = Convert.ToBase64String(AsBytes); byte[] tempBytes = Convert.FromBase64String(AsBase64String); File.WriteAllBytes(@"C:\...\file_copy.tar.gz", tempBytes); FileInfo orig = new FileInfo(@"C:\...\file.tar.gz"); FileInfo copy = new FileInfo(@"C:\...\file_copy.tar.gz");
Thank!
c # base64 streamreader
darkpbj Sep 18 '14 at 5:59 a.m. 2014-09-18 17:59
source share