def _OpenFileObject(self, path_spec): """Opens the file-like object defined by path specification. Args: path_spec: optional the path specification (instance of path.PathSpec). The default is None. Returns: A file-like object. """ gzip_file_object = resolver.Resolver.OpenFileObject( path_spec.parent, resolver_context=self._resolver_context) try: self._ReadFileHeader(gzip_file_object) self._ReadFileFooter(gzip_file_object) finally: gzip_file_object.close() path_spec_data_range = data_range_path_spec.DataRangePathSpec( range_offset=self._compressed_data_offset, range_size=self._compressed_data_size, parent=path_spec.parent) path_spec_compressed_stream = ( compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=definitions.COMPRESSION_METHOD_DEFLATE, parent=path_spec_data_range)) return resolver.Resolver.OpenFileObject( path_spec_compressed_stream, resolver_context=self._resolver_context)
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = os.path.join(u'test_data', u'syslog.bz2') path_spec = os_path_spec.OSPathSpec(location=test_file) self._compressed_stream_path_spec = ( compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=definitions.COMPRESSION_METHOD_BZIP2, parent=path_spec))
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = self._GetTestFilePath([u'syslog.lzma']) self._os_path_spec = os_path_spec.OSPathSpec(location=test_file) self._compressed_stream_path_spec = ( compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=definitions.COMPRESSION_METHOD_LZMA, parent=self._os_path_spec))
def testInitialize(self): """Tests the path specification initialization.""" path_spec = compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=u'test', parent=self._path_spec) self.assertIsNotNone(path_spec) with self.assertRaises(ValueError): _ = compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=u'test', parent=None) with self.assertRaises(ValueError): _ = compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=None, parent=self._path_spec) with self.assertRaises(ValueError): _ = compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=u'test', parent=self._path_spec, bogus=u'BOGUS')
def GetRootFileEntry(self): """Retrieves the root file entry. Returns: A file entry (instance of vfs.FileEntry) or None. """ path_spec = compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=self._compression_method, parent=self._path_spec.parent) return self.GetFileEntryByPathSpec(path_spec)
def GetRootFileEntry(self): """Retrieves the root file entry. Returns: CompressedStreamFileEntry: a file entry or None if not available. """ path_spec = compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=self._compression_method, parent=self._path_spec.parent) return self.GetFileEntryByPathSpec(path_spec)
def testComparable(self): """Tests the path specification comparable property.""" path_spec = compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=u'test', parent=self._path_spec) self.assertIsNotNone(path_spec) expected_comparable = u'\n'.join([ u'type: TEST', u'type: COMPRESSED_STREAM, compression_method: test', u'']) self.assertEqual(path_spec.comparable, expected_comparable)
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = self._GetTestFilePath(['syslog.bz2']) path_spec = os_path_spec.OSPathSpec(location=test_file) self._compressed_stream_path_spec = ( compressed_stream_path_spec.CompressedStreamPathSpec( compression_method=definitions.COMPRESSION_METHOD_BZIP2, parent=path_spec)) self._file_system = ( compressed_stream_file_system.CompressedStreamFileSystem( self._resolver_context)) self._file_system.Open(self._compressed_stream_path_spec)