Skip to content

Cannot use read method with char array as buffer? #1

@james-guevara

Description

@james-guevara

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions