Results 1 to 2 of 2

Thread: how store small file in stsdb,such as Image tiles

  1. #1
    Junior Member
    Join Date
    Jun 2014

    Default how store small file in stsdb,such as Image tiles

    By the API document,I known that w-tree store key and value all in the RAM,while I want to store image tiles(size is 256kb),if use Xtable ,it need large memory.I find that the Xfile is mentioned in the document,but the example is less.Could Xfile model solve my issue?
    if yes,give me some examples about how to save image in stsdb,and how read them.
    if not,how I can achieve my goals.
    thanks in advance.

  2. #2


    Yes, you can use XFile to store large data.

    We can work with XFile as we work with any standard .NET stream. Except one difference: the XFile is a sparse file - we can write to it and read from it at any position, including beyond the end of the file:
        using (IStorageEngine engine = STSdb.FromFile("test.stsdb4"))
            XFile stream = engine.OpenXFile("file");
            //seek beyond the end
            stream.Seek(1000, SeekOrigin.Begin);
            //write some data
            BinaryWriter writer = new BinaryWriter(stream);
            for (int i = 0; i < 100; i++)
            Console.WriteLine("Length: {0} bytes", stream.Length);
            //don't forget to commit the changes. 
    The console output in the above example will be:

    Length: 1400 bytes

    The length of the XFile is always the largest position at which the user wrote a byte (+1). The XFile supports also SetLength() method, so we can truncate the file at any position. The XFile supports also a special Zero(long count) method, by which we can easily delete very large range of data - located from the current position forward - very quickly, only with a single operation.

    The XFile is built over special XTable<long, byte[]> implementation. It contains only the actual user data. When the user reads the stream, the XFile fills on demand the empty spaces with zeroes and returns the necessary data.
    Last edited by a.todorov; 16.12.2014 at 15:14.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
2002 - 2014 STS Soft SC. All Rights reserved.
STSdb, Waterfall Tree and WTree are registered trademarks of STS Soft SC.