メモ MemoryStream + ZipArchive + CodePageEncodingProvider

.NET Core で sjis 使うには、

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

が要る。

install-package System.Text.Encoding.CodePages
using System.IO;
using System.IO.Compression;
using System.Text;

// https://stackoverflow.com/questions/17232414/creating-a-zip-archive-in-memory-using-system-io-compression
class Program
{
    static void Main(string[] args)
    {
        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

        using (var mem = new MemoryStream())
        {
            using (var archive = new ZipArchive(mem, ZipArchiveMode.Create, true, Encoding.GetEncoding("sjis")))
            {
                var f1 = archive.CreateEntry("てすと.csv");
                using (var entry = f1.Open())
                using (var writer = new StreamWriter(entry, Encoding.GetEncoding("sjis")))
                {
                    writer.Write("あいうえお,かきくけこ");
                }
            }

            using (var f = new FileStream(@"c:\temp\hoge.zip", FileMode.Create))
            {
                mem.Seek(0, SeekOrigin.Begin);
                mem.CopyTo(f);
            }
        }
    }
}