Skip to main content
Version: 3.14.x.x LTS

Transcoder object methods

MethodDescriptionSample
Utils.getTranscoder(fromEncoding, toEncoding)Instantiates a new transcoder function, which converts from "fromEncoding" to "toEncoding". This function requires the module "Utils".package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/public/Utils.lua"local Utils = require "Utils"local transcode = Utils.getTranscoder("UTF-8", "ISO-8859-1")
transcoded = transcode(value)Converts "value" from "fromEncoding" into "toEncoding".The encoded bytes are saved in "transcoded". If it was not possible to transcode the entire value, then the remaining bytes will be transcoded on the next call. If a nil value is sent, and there are still bytes left to be transcoded, an error will occur.This example converts the incoming body from "UTF-8" to "ISO-8859-1":package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/public/Utils.lua"local Utils = require "Utils"local transcode = Utils.getTranscoder("UTF-8", "ISO-8859-1")function outputStream(req, resp, chunk) return transcode(chunk) end
nevis.charset.transcoder.new(fromEncoding, toEncoding)Instantiate a new transcoder object, which converts from "fromEncoding" to "toEncoding".Only advanced users should use this transcoder. If ever possible, use the method Utils.getTranscoder().local transcoder = nevis.charset.transcoder.new("UTF-8", "ISO-8859-1")
transcoded, remaining = transcoder:transcode(value)Converts "value" from "fromEncoding" into "toEncoding".The encoded bytes are saved in "transcoded". If it was not possible to transcode the entire value, then the remaining bytes are returned in "remaining".