Ejemplo n.º 1
0
  def testRead(self):
    """Test the read functionality."""
    file_object = gzip_file_io.GzipFile(
        self._resolver_context, self._gzip_path_spec)
    file_object.Open()

    self._TestReadFileObject(file_object)
Ejemplo n.º 2
0
  def testReadMultipleMembers(self):
    """Tests reading a file that contains multiple gzip members."""
    test_file = self._GetTestFilePath(['fsevents_000000000000b208'])
    parent_path_spec = os_path_spec.OSPathSpec(location=test_file)
    path_spec = gzip_path_spec.GzipPathSpec(parent=parent_path_spec)
    file_object = gzip_file_io.GzipFile(self._resolver_context)
    file_object.open(path_spec=path_spec)

    self.assertEqual(file_object.uncompressed_data_size, 506631)
    self.assertEqual(file_object.modification_times, [0, 0])
    self.assertEqual(file_object.operating_systems, [3, 3])
    self.assertEqual(file_object.original_filenames, [None, None])
    self.assertEqual(file_object.comments, [None, None])

    file_start = file_object.read(4)
    self.assertEqual(file_start, b'1SLD')

    # Read the end of the second member
    file_object.seek(506631 - 4)
    file_end = file_object.read(4)
    self.assertEqual(file_end, b'\x02\x00\x80\x00')

    # Seek backwards, and read across a member boundary.
    file_object.seek(28530)
    self.assertEqual(file_object.read(6), b'OS\x00P\x07\x00')

    file_object.close()
Ejemplo n.º 3
0
    def testSeek(self):
        """Test the seek functionality."""
        file_object = gzip_file_io.GzipFile(self._resolver_context)
        file_object.open(path_spec=self._gzip_path_spec)

        self._TestSeekFileObject(file_object)

        file_object.close()
Ejemplo n.º 4
0
    def NewFileObject(self, resolver_context):
        """Creates a new file-like object.

    Args:
      resolver_context (Context): resolver context.

    Returns:
      FileIO: file-like object.
    """
        return gzip_file_io.GzipFile(resolver_context)
Ejemplo n.º 5
0
  def testOpenClosePathSpec(self):
    """Test the open and close functionality using a path specification."""
    file_object = gzip_file_io.GzipFile(
        self._resolver_context, self._gzip_path_spec)
    file_object.Open()

    self._TestGetSizeFileObject(file_object)

    self.assertEqual(file_object.modification_times, [0x501416d7])
    self.assertEqual(file_object.operating_systems, [0x03])
    self.assertEqual(file_object.original_filenames, ['syslog.1'])
    self.assertEqual(file_object.comments, [None])
Ejemplo n.º 6
0
    def testOpenClosePathSpec(self):
        """Test the open and close functionality using a path specification."""
        file_object = gzip_file_io.GzipFile(self._resolver_context)
        file_object.open(path_spec=self._gzip_path_spec)

        self._TestGetSizeFileObject(file_object)

        self.assertEqual(file_object.modification_time, 0x501416d7)
        self.assertEqual(file_object.operating_system, 0x03)
        self.assertEqual(file_object.original_filename, u'syslog.1')
        self.assertEqual(file_object.comment, None)

        file_object.close()
Ejemplo n.º 7
0
  def testReadCorrupt(self):
    """Tests reading a file that is corrupt."""
    # The corrupt gzip has no member footer.
    test_path = self._GetTestFilePath(['corrupt1.gz'])
    test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
        definitions.TYPE_INDICATOR_OS, location=test_path)
    test_gzip_path_spec = path_spec_factory.Factory.NewPathSpec(
        definitions.TYPE_INDICATOR_GZIP, parent=test_os_path_spec)

    file_object = gzip_file_io.GzipFile(self._resolver_context)

    with self.assertRaises(errors.FileFormatError):
      file_object.open(path_spec=test_gzip_path_spec)
Ejemplo n.º 8
0
    def testReadCorrupt(self):
        """Tests reading a file that is corrupt."""
        # The corrupt gzip has no member footer.
        test_path = self._GetTestFilePath(['corrupt1.gz'])
        self._SkipIfPathNotExists(test_path)

        test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
            definitions.TYPE_INDICATOR_OS, location=test_path)
        test_gzip_path_spec = path_spec_factory.Factory.NewPathSpec(
            definitions.TYPE_INDICATOR_GZIP, parent=test_os_path_spec)

        file_object = gzip_file_io.GzipFile(self._resolver_context)

        file_object.open(path_spec=test_gzip_path_spec)
        self.assertEqual(file_object.uncompressed_data_size, 2994187)
Ejemplo n.º 9
0
  def testReadMultipleMembers(self):
    """Tests reading a file that contains multiple gzip members."""
    test_path = self._GetTestFilePath(['fsevents_000000000000b208'])
    self._SkipIfPathNotExists(test_path)

    test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
        definitions.TYPE_INDICATOR_OS, location=test_path)
    test_gzip_path_spec = path_spec_factory.Factory.NewPathSpec(
        definitions.TYPE_INDICATOR_GZIP, parent=test_os_path_spec)

    file_object = gzip_file_io.GzipFile(self._resolver_context)
    file_object.open(path_spec=test_gzip_path_spec)

    self.assertEqual(file_object.uncompressed_data_size, 506631)
    self.assertEqual(file_object.modification_times, [0, 0])
    self.assertEqual(file_object.operating_systems, [3, 3])
    self.assertEqual(file_object.original_filenames, [None, None])
    self.assertEqual(file_object.comments, [None, None])

    file_start = file_object.read(4)
    self.assertEqual(file_start, b'1SLD')

    # Read the end of the second member
    file_object.seek(506631 - 4)
    file_end = file_object.read(4)
    self.assertEqual(file_end, b'\x02\x00\x80\x00')

    # Seek backwards, and read across a member boundary.
    file_object.seek(28530)
    self.assertEqual(file_object.read(6), b'OS\x00P\x07\x00')

    # Read with a size greater than the file size.
    file_object.seek(0)
    data = file_object.read(size=506631 + 4)
    self.assertEqual(len(data), 506631)
    self.assertEqual(data[-4:], b'\x02\x00\x80\x00')

    file_object.close()