Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array buffer allocation failed #52

Open
poberwong opened this issue Sep 29, 2018 · 0 comments
Open

Array buffer allocation failed #52

poberwong opened this issue Sep 29, 2018 · 0 comments

Comments

@poberwong
Copy link

Platform

32 bit Windows with 4 GB memory

Error log

2018-09-29 08:57:04,468: message:{msg=[***]RangeError: Array buffer allocation failed    @ new ArrayBuffer (
<anonymous>)    @ new Uint8Array (native)    @ d (https://www.***.com/static/js/main.173fa413.js:34:14944)    @ p.ArrayBu
ffer.append (https://www.****.com/static/js/main.173fa413.js:34:17224)    @ FileReader.l.onload (https://www.***.com/
static/js/main.173fa413.js:11:7385), t=1538182625000, body=, userId=139}
2018-09-29 10:27:26,023: message:{msg=[***]RangeError: Array buffer allocation failed    @ new ArrayBuffer (
<anonymous>)    @ typedArrayConstructByLength (<anonymous>)    @ new Uint8Array (native)    @ d (https://www.***.com/stat
ic/js/main.173fa413.js:34:14944)    @ p.ArrayBuffer.append (https://www.***.com/static/js/main.173fa413.js:34:17224)    @
 FileReader.l.onload (https://www.***.com/static/js/main.173fa413.js:11:7385), t=1538188042322, body=, userId=1013}

My core code

return new Promise((resolve, reject) => {
    let chunkCount = Math.ceil(file.size / hashChunkSize)
    let currentChunk = 0
    let spark = new SparkMD5.ArrayBuffer()
    let sparkArray = []
    let fileReader = new FileReader()

    fileReader.onload = function (event) {
      sparkArray.push(SparkMD5.ArrayBuffer.hash(event.target.result))
      spark.append(event.target.result)                // Append array buffer
      currentChunk++

      if (currentChunk < chunkCount) {
        loadNext()
      } else {
        resolve({
          md5: spark.end(),
          md5Array: sparkArray
        })
      }
    }

    fileReader.onerror = () => {
      reject(new Error('read file failed'))
    }

    function loadNext() {
      let start = currentChunk * hashChunkSize
      let end = ((start + hashChunkSize) >= file.size) ? file.size : start + hashChunkSize
      fileReader.readAsArrayBuffer(blobSlice.call(file, start, end))
    }

    loadNext()
  })

It seems that spark.append(event.target.result) can't get enough memory...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant