Esempio n. 1
0
    def writeFile(self, filename, stream, offset, size):
        # Create directory (only on first call)
        if not self.mkdir:
            self.createDirectory()
            self.mkdir = True

        # Create output file
        filename = path.join(self.directory, filename)
        output = FileOutputStream(filename)

        # Write output
        try:
            output.copyBytesFrom(stream, offset, size // 8)
        except StreamError as err:
            error("copyBytesFrom() error: %s" % err)
        return filename
Esempio n. 2
0
def stripEditor(editor, filename, level, verbose):
    cls = editor.input.__class__
    try:
        stripper_cls = strippers[cls]
    except KeyError:
        print("Don't have stripper for file type: %s" % editor.description)
        return False
    stripper = stripper_cls(editor, level, verbose)

    if stripper():
        output = FileOutputStream(filename)
        with output:
            editor.writeInto(output)

        size = stripper.stripped_bytes
        if size:
            percent = "%.1f%%" % (float(size) * 100 / editor.input.size)
            if size % 8 and size < 128:
                print("Remove %u.%u bytes (%s)" %
                      (size // 8, size % 8, percent))
            else:
                print("Remove %s (%s)" % (humanFilesize(size // 8), percent))
        print("Save new file into %s" % filename)
    else:
        print("Stripper doesn't touch the file")
    return True
Esempio n. 3
0
def main():
    if len(argv) != 2:
        print("usage: %s video.flv" % argv[0], file=stderr)
        exit(1)

    # Open input video
    inputname = argv[1]
    parser = createParser(inputname)
    if parser["audio[0]/codec"].value != AUDIO_CODEC_MP3:
        print("Unknown audio codec: %s" % parser["audio[0]/codec"].display,
              file=stderr)

    # Extract audio
    print("Extractor audio from: %s" % inputname)
    outputname = inputname + ".mp3"
    output = FileOutputStream(outputname)
    for chunk in parser.array("audio"):
        data = chunk["music_data"]
        output.copyBitsFrom(data.parent.stream, data.absolute_address,
                            data.size, data.parent.endian)
    print("Write audio into: %s" % outputname)
 def write(self, path, data, offset):
     if path == "/.command/writeInto":
         if self.readonly:
             return -errno.EACCES
         try:
             data = data.strip(" \t\r\n\0")
             filename = unicode(data, self.fs_charset)
         except UnicodeDecodeError:
             log.info("writeInto(): unicode error!")
             return 0
         log.info("writeInto(%s)" % filename)
         stream = FileOutputStream(filename)
         self.hachoir.writeInto(stream)
     return len(data)
Esempio n. 5
0
 def saveInto(self, filename):
     output = FileOutputStream(filename)
     self.editor.writeInto(output)
Esempio n. 6
0
def writeIntoFile(fieldset, filename):
    output = FileOutputStream(filename)
    with output:
        fieldset.writeInto(output)