encoded_base64_length#
החזרת האורך ש־encode_base64 היה מפיק, מבלי לבצע את הקידוד.
תקציר#
use MIME::Base64 qw(encoded_base64_length);
my $n = encoded_base64_length($bytes); # wrapping with "\n"
my $m = encoded_base64_length($bytes, ""); # no wrapping
my $k = encoded_base64_length($bytes, "\r\n"); # CRLF wrapping
מה מוחזר#
מספר שלם: מספר הבתים המדויק ש־encode_base64($bytes, $eol) היה מפיק, כולל כל רצף סוף־שורה. שקול ל־length(encode_base64($bytes, $eol)) אך נמנע מהקצאת המחרוזת המקודדת ומבנייתה - עדיף כאשר צריך לקבוע מראש את גודלו של buffer או לדווח על התקדמות במטען גדול.
דוגמאות#
encoded_base64_length(""); # 0
encoded_base64_length("A"); # 5 ("QQ==\n")
encoded_base64_length("A", ""); # 4 ("QQ==")
encoded_base64_length("A" x 57); # 77 (one full 76-char line + "\n")
encoded_base64_length("A" x 57, "\r\n"); # 78 (one full 76-char line + "\r\n")
מקרי קצה#
קלט ריק מחזיר
0ללא תלות בארגומנט$eol.הנוסחה היא
ceil(n/3) * 4 + lines * length($eol)כאשרlines = ceil(base_len / 76).$eolלא־מוגדר או חסר נחשב כ־"\n"(באורך 1) כדי להתאים לברירת המחדל שלencode_base64.
הבדלים מ־upstream#
תואם לחלוטין ל־MIME::Base64 שבמעלה־הזרם 3.16_01.
ראו גם#
encode_base64- הפונקציה שאורך הפלט שלה מחושב כאן.decoded_base64_length- מנבא האורך המקביל עבור המפענח.