def test_filesystem(self): hfile = Hfile(hostname, port, path, mode='w') hfile.close() fs = Hfilesystem(hostname, port) self.assertTrue(fs.exists(path)) self.assertFalse(fs.exists(path + 'doesnotexist')) self.assertTrue(fs.rename(path, path + 'renamed')) self.assertTrue(fs.delete(path + 'renamed')) self.assertFalse(fs.delete(path))
def StoreBlob(self, blob_key, blob_stream): """Store blob stream to disk. Args: blob_key: Blob key of blob to store. blob_stream: Stream or stream-like object that will generate blob content. """ logging.debug('storing blob with key %s' %blob_key) blob_key = self._BlobKey(blob_key) blob_directory = self._DirectoryForBlob(blob_key) if not self._fs.exists(blob_directory): self._fs.mkdir(blob_directory) blob_file = self._FileForBlob(blob_key) hdfs_file = Hfile(self._server, self._port, blob_file, mode='w') try: while True: block = blob_stream.read(1 << 20) if not block: break hdfs_file.write(block) finally: hdfs_file.close()
def OpenBlob(self, blob_key): """Open blob file for streaming. Args: blob_key: Blob-key of existing blob to open for reading. Returns: Open file stream for reading blob from disk. """ logging.debug('reading blob with key %s' % blob_key) return Hfile(self._server, self._port, self._FileForBlob(blob_key), mode='r')
def StoreBlob(self, blob_key, blob_stream): """Store blob stream to disk. Args: blob_key: Blob key of blob to store. blob_stream: Stream or stream-like object that will generate blob content. """ logging.debug('storing blob with key %s' % blob_key) blob_key = self._BlobKey(blob_key) blob_directory = self._DirectoryForBlob(blob_key) if not self._fs.exists(blob_directory): self._fs.mkdir(blob_directory) blob_file = self._FileForBlob(blob_key) hdfs_file = Hfile(self._server, self._port, blob_file, mode='w') try: while True: block = blob_stream.read(1 << 20) if not block: break hdfs_file.write(block) finally: hdfs_file.close()