All files / node_modules/netcdfjs/src data.js

14.28% Statements 3/21
0% Branches 0/2
0% Functions 0/2
15.78% Lines 3/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62    18x                                                                                                                 18x 18x  
'use strict';
 
const types = require('./types');
 
// const STREAMING = 4294967295;
 
/**
 * Read data for the given non-record variable
 * @ignore
 * @param {IOBuffer} buffer - Buffer for the file data
 * @param {object} variable - Variable metadata
 * @return {Array} - Data of the element
 */
function nonRecord(buffer, variable) {
  // variable type
  const type = types.str2num(variable.type);
 
  // size of the data
  var size = variable.size / types.num2bytes(type);
 
  // iterates over the data
  var data = new Array(size);
  for (var i = 0; i < size; i++) {
    data[i] = types.readType(buffer, type, 1);
  }
 
  return data;
}
 
/**
 * Read data for the given record variable
 * @ignore
 * @param {IOBuffer} buffer - Buffer for the file data
 * @param {object} variable - Variable metadata
 * @param {object} recordDimension - Record dimension metadata
 * @return {Array} - Data of the element
 */
function record(buffer, variable, recordDimension) {
  // variable type
  const type = types.str2num(variable.type);
  const width = variable.size ? variable.size / types.num2bytes(type) : 1;
 
  // size of the data
  // TODO streaming data
  var size = recordDimension.length;
 
  // iterates over the data
  var data = new Array(size);
  const step = recordDimension.recordStep;
 
  for (var i = 0; i < size; i++) {
    var currentOffset = buffer.offset;
    data[i] = types.readType(buffer, type, width);
    buffer.seek(currentOffset + step);
  }
 
  return data;
}
 
module.exports.nonRecord = nonRecord;
module.exports.record = record;