Skip to content

Streams are read until the end even if it's not necessary #682

@fl-ido

Description

@fl-ido

Hello,

The DataFilePrivate constructor always read until the end of the given stream in order to get the length of the data: https://github.com/open-eid/libdigidocpp/blob/efb30bc82d844f98fdd74102d9b63789e4a86bd4/src/DataFile.cpp#L93C1-L95C47

It is not a problem for streams coming from files on disk, as we can access them several times. However, in case of a HTTP socket for instance, we only have the data once; so, reading until the end of the stream means bufferizing the whole data in memory, which is not what we want when using streams.

I see that this size is not used for central purposes in the code, but only for tracing/testing/examples purposes. Would it be possible to move this m_size initialization to the fileSize function implementation (https://github.com/open-eid/libdigidocpp/blob/efb30bc82d844f98fdd74102d9b63789e4a86bd4/src/DataFile_p.h#L38C2-L38C57) ? By doing this, the stream would not be read by default, but only when the caller really wants to know the size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions