Lua
Lua
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Get the contents of a file into a base64 encoded string:
local fac = chilkat.FileAccess.new()
local strBase64 = fac:read_binary_to_encoded("c:/data/something.pdf", "base64")
if not fac.last_method_success then
print(fac.last_error_text)
return
end
-- Now write the string to a file:
local success = fac:write_entire_text_file("c:/data/something_pdf_base64.txt", strBase64, "us-ascii", false)
if not success then
print(fac.last_error_text)
return
end
print("Success!")