# All files / node_modules/netcdfjs/src utils.js

27.27% Statements 3/11
0% Branches 0/2
0% Functions 0/3
27.27% Lines 3/11

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

    18x
    18x
    18x
     'use strict';

    /**
     * Throws a non-valid NetCDF exception if the statement it's true
     * @ignore
     * @param {boolean} statement - Throws if true
     * @param {string} reason - Reason to throw
     */
    function notNetcdf(statement, reason) {
    I  if (statement) {
        throw new TypeError(`Not a valid NetCDF v3.x file: ${reason}`);
      }
    }

    /**
     * Moves 1, 2, or 3 bytes to next 4-byte boundary
     * @ignore
     * @param {IOBuffer} buffer - Buffer for the file data
     */
    function padding(buffer) {
    I  if ((buffer.offset % 4) !== 0) {
        buffer.skip(4 - (buffer.offset % 4));
      }
    }

    /**
     * Reads the name
     * @ignore
     * @param {IOBuffer} buffer - Buffer for the file data
     * @return {string} - Name
     */
    function readName(buffer) {
      // Read name
      var nameLength = buffer.readUint32();
      var name = buffer.readChars(nameLength);

      // validate name
      // TODO

      // Apply padding
      padding(buffer);
      return name;
    }

    module.exports.notNetcdf = notNetcdf;
    module.exports.padding = padding;
    module.exports.readName = readName;