I have been recently working on a geospatial project to extract SHP and DBF
files from zip files. For those interested the code can be found here

https://github.com/garyvidal/ml-libraries/tree/master/shpParser


In using binary data from javascript it appears that there are limited
features for binary data in MarkLogic javascript. Ideally a binary node
should have some mechanism to convert to Uint8Array or to a native
ArrayBuffer.  After experimenting a bit I was able to write some standard
functions to do this, but seems like a performance issue to marshal between
xdmp.* functions. I would prefer a native solution Chrome extensions.

Here are a few functions I think would be helpful:
atob - Array to binary (standard conversions)
btoa  Binary to Array
bin.toArrayBuffer(binary) - Returns the Uint8Array,buffer
bin.toString(encoding) - should return the string from binary based on
encoding.
TextEncoder/TextDecoder classes
Blob Support?

Any thoughts on this matter?


A few examples of things I did to support binaries in javascript (highly
experimental)

function BinToBuffer(bin) {
  var buff = xs.hexBinary(bin);
  var vals = buff.toString();
  var byteLength = vals.length / MUL;  MUL  = 2
  var buffer8 = new Uint8Array(byteLength);
  for(var byte = 0;byte <= byteLength;byte++) {
     buffer8[byte] = xdmp.hexToInteger(vals.substr((byte * MUL),MUL))
  }
  return buffer8;
}

function Utf8ArrayToStr(array) {
    var out, i, len, c;
    var char2, char3;

    out = "";
    len = array.length;
    i = 0;
    while(i < len) {
    c = array[i++];
    switch(c >> 8) //was 4
    {
      case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
        // 0xxxxxxx
        out += String.fromCharCode(c);
        break;
      case 12: case 13:
        // 110x xxxx   10xx xxxx
        char2 = array[i++];
        out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
        break;
      case 14:
        // 1110 xxxx  10xx xxxx  10xx xxxx
        char2 = array[i++];
        char3 = array[i++];
        out += String.fromCharCode(((c & 0x0F) << 12) |
                       ((char2 & 0x3F) << 6) |
                       ((char3 & 0x3F) << 0));
        break;
    }
    }

    return out;
}
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to