So, I'm iterating a file and want to chuck it into...
# suitescript
d
So, I'm iterating a file and want to chuck it into parts of 5MB (yes, to upload to S3). Suggestions on how to determine accumulated line size as I iterator?
The challenge is, I won't know the average size of a single line, nor how many total line there are (at least I don't think I can get that up front)
a
You can't use MultipartUpload or stream?
e
That's what I'm doing yes
d
I'm asking how I can chuck a NetSuite file into 5Mb chucnks
b
pick your favorite npm library to get a utf-8 string's byte length
and use that to tell the size of the string you have so far
👍 1
avoid the ones that use Buffer unless you want to use a bundler
t
Copy code
const getByteSize = (s)  => {
    return ~-encodeURI(s).split(/%..|./).length;
}
You can use this abhorrent function get find size. Can't remember how it works but probably stole it off stack overflow
As for chunking each one into exact 5Mb sizes? Don't think you can do that cause JS and browsers are inconsistent. You'll have to guess and check to my knowledge
d
Not exactly %mb, but not less than
I'll try these out .. I think I'll get into TOO MANY JAVASCRIPT EXECUTIONs for large files, but let's see
t
while (byte size < 5mb) { addline() }