Logo Search packages:      
Sourcecode: r-cran-nws version File versions  Download package

def nwsclient::NetWorkSpace::storeFile (   self,
  varName,
  fobj,
  n = -1 
)
Store a new value into a variable in the workspace from a file.

ws.storeFile(varName, fobj[, n])

Arguments:

varName -- Name of the variable.

fobj -- File to read data from to store in the variable.

n -- Number of bytes to write.  A negative value means to write
all the data in the file.

Definition at line 971 of file nwsclient.py.

                                            :
        """Store a new value into a variable in the workspace from a file.

        ws.storeFile(varName, fobj[, n])

        Arguments:

        varName -- Name of the variable.

        fobj -- File to read data from to store in the variable.

        n -- Number of bytes to write.  A negative value means to write
                all the data in the file.

        """
        if type(varName) != str:
            raise TypeError, 'variable name must be a string'

        try:
            fobj.mode.index('b')
        except:
            raise TypeError, 'fobj must be a binary mode file object'

        op = 'store'

        desc = _PythonFP | _DirectString
        descTxt = '%020u' % desc

        if n < 0:
            # determine the length of the file using stat
            # if length not specified
            # XXX this looks like it won't work on Windows
            # XXX might need to be opened in binary mode on Windows
            n = os.fstat(fobj.fileno())[stat.ST_SIZE] - fobj.tell()

        self.send('0005%020d%s%020d%s%020d%s%020d%s%020d' % (len(op), op, len(self.curWs), self.curWs, len(varName), varName, len(descTxt), descTxt, n))

        blen = 16 * 1024
        while n > 0:
            d = fobj.read(min(blen, n))
            dlen = len(d)
            if dlen <= 0:
                break
            self.send(d)
            n -= dlen

        if n > 0:
            # warning: they asked us to send more data than they had
            blen = 1024
            buffer = blen * "\0"
            while n > 0:
                if blen <= n:
                    self.send(buffer)
                    n -= dlen
                else:
                    self.send(n * "\0")
                    break

        status = int(self.recv(4))
        if status: raise NwsOperationException, 'store file failed'

Generated by  Doxygen 1.6.0   Back to index