MiniM. Saving time.


| About | Download | Tools | Knowledge Base | How to Buy |

MiniM Overview

Getting Started

Download

Documentation

Tools

Cache Tools

GT.M Tools

Knowledge Base

FAQ

Contacts

Copyrights

MiniM Knowledge Base | Nov 29, 2016

How to Save File to Global

This article describes steps to save binary files or byte sequences in globals.

To save file stored in the file system, we need to open file device in binary mode. By default file device openes in text mode. In text mode some bytes can be automatically removed from source byte sequence. In binary mode all bytes are returned by the read command.

Next point we need to define - end of file usage. Here we can use special $zeof mode or use standard error handling while we reach end of file.

Source data need to be read by some portions - chunks. File can contain megabytes of data, but read command can return only up to 32K bytes and one record in local or global variable can store only this chunk too. We need to select chunk size in bytes. Last chank can have different size than all other.

In this small example we read file from file system and store content in the global by chunks with size of 123 bytes.

binread
  s dev="|FILE|path/filename.pdf"
  n saveio=$io
  o dev:("rb")
  use dev
  k ^PDF
  n oldeof=$v("proc",5,0) ; save current zeof mode
  n chunk=123 ; here can be up to 32K
  f I=1:1 q:$zeof  d
  . r line#chunk    ; read chunk bytes
  . q:line=""
  . s ^PDF(I)=line  ; store line, last line can be less then chunk
  i $v("proc",5,oldeof) ; restore zeof mode
  close dev
  u saveio
  q

And, to retrive content of file stored in the global we must read chunk by chunk in the same sequence as it was read.

Eugene Karataev
support@minimdb.com


Copyright (C) 2017 Eugene Karataev
Emails: Info Tech Support