-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #446 from floryst/vtp_appended_format
Add vti/vtp appended data format support
- Loading branch information
Showing
7 changed files
with
229 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Converts a binary buffer in an ArrayBuffer to a string. | ||
* | ||
* Note this does not take encoding into consideration, so don't | ||
* expect proper Unicode or any other encoding. | ||
*/ | ||
function arrayBufferToString(arrayBuffer) { | ||
const byteArray = new Uint8Array(arrayBuffer); | ||
const strArr = []; | ||
for (let i = 0; i < byteArray.length; ++i) { | ||
strArr[i] = String.fromCharCode(byteArray[i]); | ||
} | ||
return strArr.join(''); | ||
} | ||
|
||
/** | ||
* Extracts binary data out of a file ArrayBuffer given a prefix/suffix. | ||
*/ | ||
function extractBinary(arrayBuffer, prefixRegex, suffixRegex = null) { | ||
const str = arrayBufferToString(arrayBuffer); | ||
|
||
const prefixMatch = prefixRegex.exec(str); | ||
if (!prefixMatch) { | ||
return { text: str }; | ||
} | ||
|
||
const dataStartIndex = prefixMatch.index + prefixMatch[0].length; | ||
const strFirstHalf = str.substring(0, dataStartIndex); | ||
let retVal = null; | ||
|
||
const suffixMatch = suffixRegex ? suffixRegex.exec(str) : null; | ||
if (suffixMatch) { | ||
const strSecondHalf = str.substr(suffixMatch.index); | ||
retVal = { | ||
text: strFirstHalf + strSecondHalf, | ||
binaryBuffer: arrayBuffer.slice(dataStartIndex, suffixMatch.index), | ||
}; | ||
} else { | ||
// no suffix, so just take all the data starting from dataStartIndex | ||
retVal = { | ||
text: strFirstHalf, | ||
binaryBuffer: arrayBuffer.slice(dataStartIndex), | ||
}; | ||
} | ||
|
||
// TODO Maybe delete the internal ref to strArr from the match objs? | ||
retVal.prefixMatch = prefixMatch; | ||
retVal.suffixMatch = suffixMatch; | ||
return retVal; | ||
} | ||
|
||
export default { | ||
arrayBufferToString, extractBinary, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.