{"id":5106,"date":"2023-01-05T11:57:12","date_gmt":"2023-01-05T03:57:12","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5106"},"modified":"2023-01-05T11:57:12","modified_gmt":"2023-01-05T03:57:12","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescript%e5%ad%97%e4%b8%b2%e7%9a%84base64%e8%a7%a3%e7%a2%bc","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescript%e5%ad%97%e4%b8%b2%e7%9a%84base64%e8%a7%a3%e7%a2%bc\/","title":{"rendered":"\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528TypeScript\u5b57\u4e32\u7684base64\u89e3\u78bc"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, base64, decodeBase64\"><\/p>\n<h1>TypeScript \u5b57\u4e32\u7684 base64 \u89e3\u78bc(decodeBase64)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709\u66f4\u591a\u7684\u529f\u80fd\uff0c\u5176\u4e2d\u4e00\u500b\u529f\u80fd\u5c31\u662f\u53ef\u4ee5\u5c0d\u5b57\u4e32\u9032\u884c base64 \u89e3\u78bc\uff0c\u4e5f\u5c31\u662f decodeBase64\u3002<\/p>\n<p>base64 \u662f\u4e00\u7a2e\u7de8\u78bc\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5c07\u4efb\u610f\u9577\u5ea6\u7684\u4e8c\u9032\u5236\u8cc7\u6599\u7de8\u78bc\u6210\u53ef\u8b80\u7684\u5b57\u4e32\uff0c\u800c decodeBase64 \u5247\u662f\u5c07 base64 \u7de8\u78bc\u7684\u5b57\u4e32\u89e3\u78bc\u6210\u539f\u672c\u7684\u4e8c\u9032\u5236\u8cc7\u6599\u3002<\/p>\n<p>TypeScript \u4e2d\u7684 decodeBase64 \u65b9\u6cd5\u53ef\u4ee5\u5c07 base64 \u7de8\u78bc\u7684\u5b57\u4e32\u89e3\u78bc\u6210\u539f\u672c\u7684\u4e8c\u9032\u5236\u8cc7\u6599\uff0c\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet encodedString = 'SGVsbG8gV29ybGQ=';\nlet decodedString = Buffer.from(encodedString, 'base64').toString('utf8');\nconsole.log(decodedString); \/\/ \u8f38\u51fa\uff1aHello World\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u5148\u5b9a\u7fa9\u4e86\u4e00\u500b base64 \u7de8\u78bc\u7684\u5b57\u4e32\uff0c\u7136\u5f8c\u4f7f\u7528 <code>Buffer.from()<\/code> \u65b9\u6cd5\u5c07\u5b83\u89e3\u78bc\u6210\u539f\u672c\u7684\u4e8c\u9032\u5236\u8cc7\u6599\uff0c\u6700\u5f8c\u518d\u4f7f\u7528 <code>toString()<\/code> \u65b9\u6cd5\u5c07\u5b83\u8f49\u63db\u6210\u5b57\u4e32\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u539f\u672c\u7684\u5b57\u4e32\u4e86\u3002<\/p>\n<p>decodeBase64 \u65b9\u6cd5\u53ef\u4ee5\u8b93\u6211\u5011\u5c07 base64 \u7de8\u78bc\u7684\u5b57\u4e32\u89e3\u78bc\u6210\u539f\u672c\u7684\u4e8c\u9032\u5236\u8cc7\u6599\uff0c\u9019\u5c0d\u65bc\u6211\u5011\u5728\u958b\u767c\u61c9\u7528\u7a0b\u5f0f\u6642\uff0c\u5c24\u5176\u662f\u5728\u8655\u7406\u52a0\u5bc6\u8cc7\u6599\u6642\uff0c\u53ef\u4ee5\u7bc0\u7701\u4e0d\u5c11\u6642\u9593\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u53e6\u5916\uff0cTypeScript \u4e2d\u7684 decodeBase64 \u65b9\u6cd5\u4e5f\u53ef\u4ee5\u7528\u65bc\u5c0d\u5716\u7247\u9032\u884c\u7de8\u78bc\uff0c\u53ef\u4ee5\u5c07\u5716\u7247\u8f49\u63db\u6210 base64 \u7de8\u78bc\u7684\u5b57\u4e32\uff0c\u7136\u5f8c\u518d\u5c07\u5b83\u89e3\u78bc\u6210\u539f\u672c\u7684\u5716\u7247\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u5c07\u5716\u7247\u5132\u5b58\u5728\u8cc7\u6599\u5eab\u4e2d\uff0c\u800c\u4e0d\u9700\u8981\u5132\u5b58\u5728\u786c\u789f\u4e0a\uff0c\u9019\u5c0d\u65bc\u6211\u5011\u5728\u958b\u767c\u61c9\u7528\u7a0b\u5f0f\u6642\uff0c\u53ef\u4ee5\u7bc0\u7701\u4e0d\u5c11\u7a7a\u9593\u3002<\/p>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0cTypeScript \u4e2d\u7684 decodeBase64 \u65b9\u6cd5\u53ef\u4ee5\u8b93\u6211\u5011\u5c07 base64 \u7de8\u78bc\u7684\u5b57\u4e32\u89e3\u78bc\u6210\u539f\u672c\u7684\u4e8c\u9032\u5236\u8cc7\u6599\uff0c\u5c0d\u65bc\u6211\u5011\u5728\u958b\u767c\u61c9\u7528\u7a0b\u5f0f\u6642\uff0c\u53ef\u4ee5\u7bc0\u7701\u4e0d\u5c11\u6642\u9593\u548c\u7a7a\u9593\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528TypeScript\u5b57\u4e32\u7684base64\u89e3\u78bc\uff0c\u4e86\u89e3base64\u89e3\u78bc\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528TypeScript\u4f86\u5be6\u73febase64\u89e3\u78bc\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5106","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1km","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5106"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5106\/revisions"}],"predecessor-version":[{"id":5107,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5106\/revisions\/5107"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}