ascii-grid
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "ascii-grid", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Identify and Read an ARC/INFO ASCII Grid", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -1,8 +0,8 @@ | ||
const MAX_READ_LENGTH = 500; | ||
module.exports = (input, options = {}) => { | ||
const debug = options.debug || false; | ||
const max_read_length = options.max_read_length || 500; | ||
if (typeof Buffer !== "undefined" && Buffer.isBuffer(input)) { | ||
if (input.toString) { | ||
input = input.toString("utf8", 0, MAX_READ_LENGTH); | ||
input = input.toString("utf8", 0, max_read_length); | ||
if (debug) console.log("converted input to a string"); | ||
@@ -20,3 +20,3 @@ } else { | ||
const decoded = ""; | ||
const length = Math.min(MAX_READ_LENGTH, input.byteLength); | ||
const length = Math.min(max_read_length, input.byteLength); | ||
for (let i = 0; i < length; i++) { | ||
@@ -29,4 +29,4 @@ decoded += String.fromCharCode(input.getUint8(i)); | ||
if (input instanceof Uint8Array) { | ||
const decoded = ""; | ||
for (let i = 0; i < Math.min(MAX_READ_LENGTH, input.length); i++) { | ||
let decoded = ""; | ||
for (let i = 0; i < Math.min(max_read_length, input.length); i++) { | ||
decoded += String.fromCharCode(input[i]); | ||
@@ -33,0 +33,0 @@ } |
@@ -19,3 +19,4 @@ const { readFileSync } = require("fs"); | ||
const bufferIsAsciiGrid = isAsciiGrid(buffer, { debug: false }); | ||
t.is(bufferIsAsciiGrid, true); | ||
t.true(bufferIsAsciiGrid); | ||
t.true(isAsciiGrid(Uint8Array.from(buffer))); | ||
}); | ||
@@ -22,0 +23,0 @@ |
13254
139