Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arrayloader

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arrayloader

Data reading utility (including TypedArray), Browserify aware

  • 5.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by20%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 17 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc