 nd = require('./ndarray')
-
-print = (arr) ->
-
-    if !arr instanceof nd.NDArray
-        throw 'argument is not a NDArray object'
-
-    dataStr = '['
-    for n in [0...arr.length]
-        dataStr += arr.data[n] +  (if n < arr.length-1 then ', ' else '')
-    dataStr += ']'
-
-    console.log(dataStr)
 
 
 ###



###
Transform an array containing UTF-8 character codes to string

The code is based on the answer provided in StackOverflow: 
http://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326

@param [Uint8Array] codeBuffer UTF-8 characters code buffer
@param [int, optional] chunk  Chunk size to which the conversion
  is applied at once.

@return [String] encoded string
###
utf8CodeToString = (codeBuffer, chunk=0x8000) ->

    strList = []
    for n in [0...codeBuffer.byteLength] by chunk
        strList.push(String.fromCharCode.apply(null, codeBuffer.subarray(n, n+chunk)))

    return strList.join('')


###
Return an ArrayBuffer object with data 
###
fromBase64 = (str) ->

    for c in str
        console.log(c)


module.exports = 
    print : print
    toBase64 : toBase64
    fromBase64 : fromBase64
# get char codes from base64Code
for i in [0...base64Code.length]
    base64CharCode[i] = base64Code.charCodeAt(i)


###
Print a NDArray to console

@param [NDArray] arr NDArray to print.

###
print = (arr) ->

    if !arr instanceof nd.NDArray
        throw 'argument is not a NDArray object'

    dataStr = '['
    for n in [0...arr.length]
        dataStr += arr.data[n] +  (if n < arr.length-1 then ', ' else '')
    dataStr += ']'

    console.log(dataStr)

###
Print the bytes of a NDArray in hexadecimal code.

@param [NDArray] arr NDArray.
###
printHex = (arr) ->
    view = new Uint8Array(arr.buffer)

    str = ''
    for b in view
        str += b.toString(16)

    return str


###
Transform an array containing UTF-8 character codes to string

The code is based on the answer provided in StackOverflow: 
http://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326

@param [Uint8Array] codeBuffer UTF-8 characters code buffer
@param [int, optional] chunk  Chunk size to which the conversion
  is applied at once.

@return [String] encoded string
###
utf8CodeToString = (codeBuffer, chunk=0x8000) ->

    strList = []
    for n in [0...codeBuffer.byteLength] by chunk
        strList.push(String.fromCharCode.apply(null, codeBuffer.subarray(n, n+chunk)))

    return strList.join('')


###
