arrayloader
Data reading utility (including TypedArray), Browserify aware
Last updated a year ago by waylonflinn .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install arrayloader 
SYNC missed versions from official npm registry.

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,

extension TypedArray numpy dtype mime type
i8 Int8Array int8 application/x-int8
u8 Uint8Array uint8 application/x-uint8
i16 Int16Array int16 application/x-int16
u16 Uint16Array uint16 application/x-uint16
i32 Int32Array int32 application/x-int32
u32 Uint32Array uint32 application/x-uint32
f32 Float32Array float32 application/x-float32
f64 Float64Array float64 application/x-float64

or (for non-binary types) like this,

extension type mime type
json json application/json
key json application/json
txt str text/plain
csv str text/plain
tsv str text/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

Current Tags

  • 5.0.0                                ...           latest (a year ago)

16 Versions

  • 5.0.0                                ...           a year ago
  • 4.0.2                                ...           2 years ago
  • 4.0.1                                ...           3 years ago
  • 4.0.0                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 2.2.2                                ...           3 years ago
  • 2.2.1                                ...           3 years ago
  • 2.1.1                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 4
Dependencies (2)
Dev Dependencies (2)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |