previousblock

Information on previous block in blocked file-set

Description

example

blkInfo = previousblock(bs) returns the information on the previous block in the BlockedFileSet object bs, then recedes the internal pointer of the blocked file-set to the previous block. Subsequent calls to the previousblock function continue reading from the endpoint of the previous call.

Examples

collapse all

Return to a previous block in a blocked file-set to get block information.

Create a blocked file-set bs for a collection of blocks.

folder = {'accidents.mat','airlineResults.mat','census.mat','earth.mat'}
folder = 1x4 cell
  Columns 1 through 3

    {'accidents.mat'}    {'airlineResults...'}    {'census.mat'}

  Column 4

    {'earth.mat'}

bs = matlab.io.datastore.BlockedFileSet(folder)
bs = 
  BlockedFileSet with properties:

                   NumBlocks: 4
               NumBlocksRead: 0
                   BlockSize: 'file'
                   BlockInfo: Show BlockInfo for all 4 blocks
    AlternateFileSystemRoots: {}

Get the information for the first block and move the internal pointer forward one block.

blk1 = nextblock(bs)
blk1 = 
  1x1 BlockInfo
                                       Filename                                       FileSize    OffSet    BlockSize
    ______________________________________________________________________________    ________    ______    _________

    "/mathworks/devel/bat/Bdoc20a/build/matlab/toolbox/matlab/demos/accidents.mat"      7343        0         7343   

Get information for the second block and move the internal pointer forward one block.

blk2 = nextblock(bs)
blk2 = 
  1x1 BlockInfo
                                         Filename                                           FileSize     OffSet    BlockSize 
    ___________________________________________________________________________________    __________    ______    __________

    "/mathworks/devel/bat/Bdoc20a/build/matlab/toolbox/matlab/demos/airlineResults.mat"    1.5042e+05      0       1.5042e+05

Get information for the second block again and recede the internal pointer to the second block.

prev = previousblock(bs)
prev = 
  1x1 BlockInfo
                                         Filename                                           FileSize     OffSet    BlockSize 
    ___________________________________________________________________________________    __________    ______    __________

    "/mathworks/devel/bat/Bdoc20a/build/matlab/toolbox/matlab/demos/airlineResults.mat"    1.5042e+05      0       1.5042e+05

Input Arguments

collapse all

Blocked file-set, specified as a matlab.io.datastore.BlockedFileSet object. To create a BlockedFileSet object, see matlab.io.datastore.BlockedFileSet.

Example: hasPreviousBlock(bs)

Output Arguments

collapse all

This property is read-only.

Information about blocks in the BlockedFileSet object, returned as a BlockInfo object with the following properties:

  • Filename — Name of the file in the BlockedFileSet object. The name contains the full path of the file.

  • FileSize — Size of the file in number of bytes.

  • Offset — Starting offset within the file to be read.

  • BlockSize — Size of the block in number of bytes.

Tips

  • The previousblock method returns an error if no blocks have been read from the BlockedFileSet object bs. To avoid this error, you can use previousblock along with hasPreviousBlock and reset. The hasPreviousBlock method checks if blocks still remain that were previously read from the BlockedFileSet object, while the reset method resets the internal pointer to the beginning of the BlockedFileSet object.

Introduced in R2020a