יחידה:Base64/תיעוד

מתוך ויקיפדיה, האנציקלופדיה החופשית

זהו דף התיעוד עבור יחידה:Base64

היחידה מספקת שתי פונקציות, לשימוש ביחידות אחרות. שתי הפונקציות עושות encode ו-decode ל-Base64. פונקציית ה-decode מקבלת שני פרמטרים, הראשון שולט על פענוח decodeURIComponent, והשני שולט על פענוח JSON: אם הפרמטר השני מתפרש כ-true, הקריאה תנסה להפוך JSON לטבלה של לואה, כפי שמתואר ב-mw:Extension:Scribunto/Lua reference manual#mw.text.jsonDecode.

דוגמה לשימוש

local parser = require( 'Module:Base64' )

-- encoding a string into base64 blob

local blob = parser.encode( "some arbitrary string. must be string (made of 8-bit chars) and not ustring!" )

-- received a a blob from somewhere
local str = parser.decode( blob )

-- received a blob that represents ustring encoded with encodeURIComponent
local ustr = parser.decode( blob, true )

-- received a blob that represents json structure containing ustrings encoded with encodeURIComponent
local luaTable = parser.decode( blob, true, true )

קוד היחידה