123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
/*******************************************************************************

        copyright:      Copyright (c) 2007 Kris Bell. All rights reserved

        license:        BSD style: $(LICENSE)

        version:        Initial release: Nov 2007

        author:         Kris

*******************************************************************************/

module tango.io.stream.DataFile;

private import tango.io.device.File;

private import tango.io.stream.Data;

/*******************************************************************************

        Composes a seekable file with buffered binary input. A seek causes
        the input buffer to be cleared.

*******************************************************************************/

class DataFileInput : DataInput
{
        private File conduit;

        /***********************************************************************

                Compose a FileStream.

        ***********************************************************************/

        this (char[] path, File.Style style = File.ReadExisting)
        {
                this (new File (path, style));
        }

        /***********************************************************************

                Wrap a File instance.

        ***********************************************************************/

        this (File file)
        {
                super (conduit = file);
        }

        /***********************************************************************

                Return the underlying conduit.

        ***********************************************************************/

        final File file ()
        {
                return conduit;
        }
}


/*******************************************************************************

        Composes a seekable file with buffered binary output. A seek causes
        the output buffer to be flushed first.

*******************************************************************************/

class DataFileOutput : DataOutput
{
        private File conduit;

        /***********************************************************************

                Compose a FileStream.

        ***********************************************************************/

        this (char[] path, File.Style style = File.WriteCreate)
        {
                this (new File (path, style));
        }

        /***********************************************************************

                Wrap a FileConduit instance.

        ***********************************************************************/

        this (File file)
        {
                super (conduit = file);
        }

        /***********************************************************************

                Return the underlying conduit.

        ***********************************************************************/

        final File file ()
        {
                return conduit;
        }
}

debug (DataFile)
{
        import tango.io.Stdout;

        void main()
        {
                auto myFile = new DataFileOutput("Hello.txt");
                myFile.write("some text");
                myFile.flush;
                Stdout.formatln ("{}:{}", myFile.file.position, myFile.seek(myFile.Anchor.Current));
        }
}