From f4c041abdf0eaa87c09a2c2403fd458576c87d7c Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 1 Sep 2016 23:37:57 -0600 Subject: [PATCH] Better sliceAtEOF() --- core/art.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/art.js b/core/art.js index 24ce8bcc..22408cc9 100644 --- a/core/art.js +++ b/core/art.js @@ -47,10 +47,11 @@ function getFontNameFromSAUCE(sauce) { } function sliceAtEOF(data, eofMarker) { - var eof = data.length; - // :TODO: max scan back or other beter way of doing this?! - for(var i = data.length - 1; i > 0; i--) { - if(data[i] === eofMarker) { + let eof = data.length; + const stopPos = Math.max(data.length - (256), 0); // 256 = 2 * sizeof(SAUCE) + + for(let i = eof - 1; i > stopPos; i--) { + if(eofMarker === data[i]) { eof = i; break; }