GithubHelp home page GithubHelp logo

johnnovak / nim-binstreams Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 2.0 122 KB

Endianness aware binary streams for Nim

License: Do What The F*ck You Want To Public License

Nim 100.00%
binary-stream endianness nim nim-lang streams

nim-binstreams's People

Contributors

johnnovak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

ac2pic exstrim401

nim-binstreams's Issues

Cannot use read method with char array as buffer?

Hi, just wondering if it should be possible to read a filestream and put the result into a char array. I'm trying to run something like this:

import binstreams
import os

var fs = newFileStream(paramStr(1), endian = bigEndian, mode = fmRead)

var buf: array[2, char]
fs.read(buf, startIndex = 0, numValues = 2)

But I'm getting this error:

/Users/owner/tiff_parser/endian_test.nim(9, 3) Error: type mismatch: got <FileStream, array[0..1, char], startIndex: int literal(0), numValues: int literal(2)>
but expected one of: 
proc read(fs: FileStream; T: typedesc[SomeNumber]): T:type
  first type mismatch at position: 2
  required type for T: type SomeNumber
  but expression 'buf' is of type: array[0..1, char]
proc read[T: SomeNumber](fs: FileStream; buf: var openArray[T];
                         startIndex, numValues: Natural)
  first type mismatch at position: 2
  required type for buf: var openArray[T: SomeNumber]
  but expression 'buf' is of type: array[0..1, char]
2 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them

expression: read(fs, buf, startIndex = 0, numValues = 2)

It says the required type of T should be SomeNumber, but wondering if it could also be made to work with char arrays or if there's a reason why it can't work with other kinds of arrays? Or perhaps there are better alternate methods I could use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.