{"id":602,"date":"2022-12-14T16:42:43","date_gmt":"2022-12-14T07:42:43","guid":{"rendered":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=602"},"modified":"2022-12-14T16:42:43","modified_gmt":"2022-12-14T07:42:43","slug":"ziparchive%e3%81%ab%e3%82%88%e3%82%8b%e3%80%81zip%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ae%e4%bd%9c%e6%88%90","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=602","title":{"rendered":"ZipArchive\u306b\u3088\u308b\u3001ZIP\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210"},"content":{"rendered":"\n<p>Zip\u30d5\u30a1\u30a4\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3057\u3066\u306fDotNetZip\u304c\u6709\u540d\u3060\u304c\u3001.NET\u6a19\u6e96\u306eSystem.IO.Compression.ZipArchive\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u305f\u3001ZIP\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u306b\u3064\u3044\u3066\u306e\u5099\u5fd8\u9332\u3092\u66f8\u3044\u3066\u307f\u3088\u3046\u3068\u601d\u3046\u3002<\/p>\n\n\n\n<p>\u306a\u305c\u3001ZipArchive\u3092\u5229\u7528\u3057\u3088\u3046\u3068\u3057\u305f\u306e\u304b\u3068\u3044\u3046\u3068\u3001\u6700\u521d\u306fDotNetZip\u3092\u4f7f\u3063\u3066\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u305f\u306e\u3060\u304c\u3001Web\u30da\u30fc\u30b8\u304b\u3089\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u3046\u307e\u304f\u52d5\u4f5c\u305b\u305a\u3001\u539f\u56e0\u3092\u7a81\u304d\u6b62\u3081\u308b\u3088\u308a\u3001\u5225\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u305f\u65b9\u304c\u65e9\u3044\u304b\u306a\u3068\u3044\u3046\u611f\u3058\u3067\u3001\u8272\u3005\u8abf\u3079\u3066\u307f\u305f\u306e\u3060\u304c\u3001\u307e\u3041\u3001.NET\u6a19\u6e96\u3060\u3057\u3001\u3053\u308c\u3067\u3044\u3044\u304b\u306a\u3068\u63a1\u7528\u3057\u305f\u308f\u3051\u3002<\/p>\n\n\n\n<p>ZIP\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u306b\u306f\u3001ZipFile\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u305f\u65b9\u304c\u7c21\u5358\u306a\u306e\u3060\u304c\u3001\u4eca\u56de\u306fWeb\u30a2\u30d7\u30ea\u3067\u3001\u52d5\u7684\u306b\u4f5c\u6210\u3057\u305f\u5185\u5bb9\u3092Zip\u5316\u3057\u305f\u3044\u306e\u3067\u3001ZipArchive\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n\n\n\n<p>ZipArchive\u30af\u30e9\u30b9\u306f\u66f8\u8fbc\u5148\u3068\u306a\u308bStream\u3092\u6307\u5b9a\u3057\u3066\u4f5c\u6210\u3059\u308b\u3002\u305d\u306e\u4e2d\u306b\u30a8\u30f3\u30c8\u30ea\u3092\u8ffd\u52a0\u3057\u3066\u884c\u304f\u5f62\u3060\u3002<\/p>\n\n\n\n<p>\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3092\u898b\u3066\u307f\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"ZipArchive\u4f8b\" data-lang=\"C#\"><code>using System.IO;\nusing System.IO.Compression;\n\u30fb\u30fb\u30fb\nusing(MemoryStream zipstream = new MemoryStream()) {\t\/\/ ZipArchive\u3092\u66f8\u8fbc\u3080Stream\n\tusing(ZipArchive ar = new ZipArchive(zipstream,ZipArchiveMode.Create,true)) {\t\/\/ ZipArchive\u306e\u4f5c\u6210\n\t\t\/\/ ZipEntry=\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\n\t\tZipArchiveEntry ent = ar.CreateEntry(entry1);\n\t\tusing(Stream stm = ent.Open()) { \/\/ \u30a8\u30f3\u30c8\u30ea\u306eStream\u3092\u53d6\u5f97\n\t\t\tusing(StreamWriter wtr = new StreamWriter(stm,Encoding.GetEncoding(&quot;shift_jis&quot;))) {\t\/\/ \u6587\u5b57\u5217\u66f8\u304d\u8fbc\u307f\u7528StreamWriter\n\t\t\t\t\/\/ \u30d5\u30a1\u30a4\u30eb\u5185\u5bb9\u4f5c\u6210\n\t\t\t\t\u30fb\u30fb\u30fb\n\t\t\t\tawait wtr.FlushAsync();\n\t\t\t\tawait stm.FlushAsync();\n\t\t\t}\n\t\t}\n\t\t\/\/ \u5fc5\u8981\u5206\u4e0a\u8a18\u306e\u7e70\u8fd4\u3057\n\t\t\u30fb\u30fb\u30fb\n\t}\n\tawait zipstream.FlushAsync();\n\tbyte[] buff = zipstream.ToArray();\n\treturn File(buff,&quot;application\/octet-stream&quot;,ZipFileName);\n}<\/code><\/pre><\/div>\n\n\n\n<p>DotNetZip\u3068\u6bd4\u3079\u308b\u3068\u591a\u5c11\u9762\u5012\u3067\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u3051\u3089\u308c\u306a\u3044\u7b49\u306e\u554f\u984c\u3082\u3042\u308b\u3051\u3069\u3001\u76ee\u7684\u304c\u679c\u305f\u305b\u305f\u304b\u3089\u826f\u3057\u3068\u3057\u3088\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Zip\u30d5\u30a1\u30a4\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3057\u3066\u306fDotNetZip\u304c\u6709\u540d\u3060\u304c &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=602\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,9,4],"tags":[],"class_list":["post-602","post","type-post","status-publish","format-standard","hentry","category-net","category-c","category-4"],"_links":{"self":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=602"}],"version-history":[{"count":1,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions"}],"predecessor-version":[{"id":603,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions\/603"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}