5.0.0 • Published 5 years ago

arrayloader v5.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

arrayloader

TypedArray reading utility, Browserify aware.

Uses fs.readFile in node, and XHR when browserified.

Installation

npm install arrayloader

Example

var loader = require('arrayloader');
loader.load('/path/to/array.f32', function (err, arr) {
	// arr is a Float32Array
	console.log(arr);
});

write compatible arrays from numpy like this,

# given array 'a'
with open('/path/to/array.f32', 'wb') as f:
	f.write(a.astype(np.float32).tostring())

choose an extension for your file like this,

extensionTypedArraynumpy dtypemime type
i8Int8Arrayint8application/x-int8
u8Uint8Arrayuint8application/x-uint8
i16Int16Arrayint16application/x-int16
u16Uint16Arrayuint16application/x-uint16
i32Int32Arrayint32application/x-int32
u32Uint32Arrayuint32application/x-uint32
f32Float32Arrayfloat32application/x-float32
f64Float64Arrayfloat64application/x-float64

or (for non-binary types) like this,

extensiontypemime type
jsonjsonapplication/json
keyjsonapplication/json
txtstrtext/plain
csvstrtext/plain
tsvstrtext/plain

Extensions mapped to json will be parsed (with JSON.parse) before returning.

Details

This module can read text and binary files. It will attempt to infer type from the extension of the file. If the extension isn't recognized, the type defaults to Uint8Array.

Type inference can be overridden by supplying a second argument. If this argument is supplied but not recognized, the function returns immediately with an error. If supplied, this argument should be a string containing any of the values listed in the "numpy dtype" column from the first table or the "type" column from the second.

Extras

Files in this format can be read into python/numpy like this,

with open(doc_dir + 'array.f32', 'rb') as f:
    a = np.fromstring(f.read(), dtype="float32")

Notes

Extensions for binary types differ from the numpy dtype short form in one way. The numpy short dtype specifies number of bytes, this module uses the number of bits (just as in the long form).

Credits

based on the simple, but fantastic floader

5.0.0

5 years ago

4.0.2

6 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.1.0

7 years ago

3.0.1

7 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago