#ifndef __MORDOR_LIMITED_STREAM_H__
#define __MORDOR_LIMITED_STREAM_H__
// Copyright (c) 2009 - Mozy, Inc.

#include "filter.h"

namespace Mordor {

class LimitedStream : public MutatingFilterStream
{
public:
    typedef boost::shared_ptr<LimitedStream> ptr;

public:
    LimitedStream(Stream::ptr parent, long long size, bool own = true);

    bool strict() { return m_strict; }
    void strict(bool strict) { m_strict = strict; }

    bool supportsSeek() { return parent()->supportsSeek(); }
    bool supportsTell() { return true; }
    bool supportsSize() { return true; }
    bool supportsTruncate() { return false; }

    size_t read(Buffer &b, size_t len);
    size_t write(const Buffer &b, size_t len);
    long long seek(long long offset, Anchor anchor = BEGIN);
    long long size();
    void truncate(long long size);
    void unread(const Buffer &b, size_t len);

private:
    long long m_pos, m_size;
    bool m_strict;
};

}

#endif

#ifndef __MORDOR_LIMITED_STREAM_H__
#define __MORDOR_LIMITED_STREAM_H__
// Copyright (c) 2009 - Mozy, Inc.

#include "filter.h"

namespace Mordor {

class LimitedStream : public MutatingFilterStream
{
public:
    typedef boost::shared_ptr<LimitedStream> ptr;

public:
    LimitedStream(Stream::ptr parent, long long size, bool own = true);

    void reset() { m_pos = 0; }
    void reset(long long size) { m_pos = 0; m_size = size; }

    bool strict() { return m_strict; }
    void strict(bool strict) { m_strict = strict; }

    bool supportsSeek() { return parent()->supportsSeek(); }
    bool supportsTell() { return true; }
    bool supportsSize() { return true; }
    bool supportsTruncate() { return false; }

    size_t read(Buffer &b, size_t len);
    size_t write(const Buffer &b, size_t len);
    long long seek(long long offset, Anchor anchor = BEGIN);
    long long size();
    void truncate(long long size);
    void unread(const Buffer &b, size_t len);

private:
    long long m_pos, m_size;
    bool m_strict;
};

}

#endif

Support for resetting a LimitedStream
Support for resetting a LimitedStream

Both current position, and total length.

Change-Id: Ia484e8b91e98d8cd2153496cbb1d5b183dacb14f
Reviewed-on: https://gerrit.dechocorp.com/8980
Reviewed-by: Punky Brewster (labs admin) <4fefd66e0791c836d3da15985fe778b56ecb4b1b@example.com>
Reviewed-by: Jeremy Stanley <b3f594e10a9edcf5413cf1190121d45078c62290@mozy.com>
