3 # zfec -- a fast C implementation of Reed-Solomon erasure coding with
4 # command-line, C, and Python interfaces
8 from util import argparse
11 from zfec import __version__ as libversion
12 from util.version import Version
13 __version__ = Version("1.0.0a1-0-STABLE")
16 if '-V' in sys.argv or '--version' in sys.argv:
17 print "zfec library version: ", libversion
18 print "zunfec command-line tool version: ", __version__
21 parser = argparse.ArgumentParser(description="Decode data from share files.")
23 parser.add_argument('-o', '--outputfile', required=True, help='file to write the resulting data to, or "-" for stdout', type=str, metavar='OUTF')
24 parser.add_argument('sharefiles', nargs='*', help='shares file to read the encoded data from', type=unicode, metavar='SHAREFILE')
25 parser.add_argument('-v', '--verbose', help='print out messages about progress', action='store_true')
26 parser.add_argument('-f', '--force', help='overwrite any file which already in place of the output file', action='store_true')
27 parser.add_argument('-V', '--version', help='print out version number and exit', action='store_true')
28 args = parser.parse_args()
30 if len(args.sharefiles) < 2:
31 print "At least two sharefiles are required."
35 outf = open(args.outputfile, 'wb')
38 flags = os.O_WRONLY|os.O_CREAT|os.O_EXCL | (hasattr(os, 'O_BINARY') and os.O_BINARY)
39 outfd = os.open(args.outputfile, flags)
41 print "There is already a file named %r -- aborting. Use --force to overwrite." % (args.outputfile,)
43 outf = os.fdopen(outfd, "wb")
46 # This sort() actually matters for performance (shares with numbers < k
47 # are much faster to use than the others), as well as being important for
49 args.sharefiles.sort()
50 for fn in args.sharefiles:
51 sharefs.append(open(fn, 'rb'))
53 ret = filefec.decode_from_files(outf, sharefs, args.verbose)
54 except filefec.InsufficientShareFilesError, e:
60 # zfec -- fast forward error correction library with Python interface
62 # Copyright (C) 2007 Allmydata, Inc.
63 # Author: Zooko Wilcox-O'Hearn
65 # This file is part of zfec.
67 # This program is free software; you can redistribute it and/or modify it
68 # under the terms of the GNU General Public License as published by the Free
69 # Software Foundation; either version 2 of the License, or (at your option)
70 # any later version, with the added permission that, if you become obligated
71 # to release a derived work under this licence (as per section 2.b), you may
72 # delay the fulfillment of this obligation for up to 12 months. See the file
73 # COPYING for details.
75 # If you would like to inquire about a commercial relationship with Allmydata,
76 # Inc., please contact partnerships@allmydata.com and visit
77 # http://allmydata.com/.