* check if utf8 chars being split, if does, stripe the bytes and add to left buffer.
(chunk: Buffer, runtime: ParseRuntime)
| 43 | * check if utf8 chars being split, if does, stripe the bytes and add to left buffer. |
| 44 | */ |
| 45 | function cleanUtf8Split(chunk: Buffer, runtime: ParseRuntime): Buffer { |
| 46 | let idx = chunk.length - 1; |
| 47 | /** |
| 48 | * From Keyang: |
| 49 | * The code below is to check if a single utf8 char (which could be multiple bytes) being split. |
| 50 | * If the char being split, the buffer from two chunk needs to be concat |
| 51 | * check how utf8 being encoded to understand the code below. |
| 52 | * If anyone has any better way to do this, please let me know. |
| 53 | */ |
| 54 | if ((chunk[idx] & 1 << 7) != 0) { |
| 55 | while ((chunk[idx] & 3 << 6) === 128) { |
| 56 | idx--; |
| 57 | } |
| 58 | idx--; |
| 59 | } |
| 60 | if (idx != chunk.length - 1) { |
| 61 | runtime.csvLineBuffer = chunk.slice(idx + 1); |
| 62 | return chunk.slice(0, idx + 1) |
| 63 | // var _cb=cb; |
| 64 | // var self=this; |
| 65 | // cb=function(){ |
| 66 | // if (self._csvLineBuffer){ |
| 67 | // self._csvLineBuffer=Buffer.concat([bufFromString(self._csvLineBuffer,"utf8"),left]); |
| 68 | // }else{ |
| 69 | // self._csvLineBuffer=left; |
| 70 | // } |
| 71 | // _cb(); |
| 72 | // } |
| 73 | } else { |
| 74 | return chunk; |
| 75 | } |
| 76 | } |