Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import compressor,sys,os
- usg ="""usage:
- python filecut.py <path> <blocksize>
- example: python filecut.py example.jpg 6
- """
- try:
- opened = sys.argv[1]
- except:
- print usg
- os.system("pause")
- sys.exit(0)
- try:
- lev = sys.argv[2]
- lev = int(lev)
- display = False
- except ValueError:
- sys.exit(0)
- except:
- display = True
- levels = {
- 1:1024,
- 2:2048,
- 3:4096,
- 4:8192,
- 5:16384,
- 6:32768,
- 7:65536,
- 8:131072,
- 9:262144,
- 10:524288
- }
- if display: #if accessed through command line or by dragging.
- for i in levels:
- print str(i),":",str(levels[i])
- choose = raw_input("\nChoose block size (1 through 10)\n")
- def begin(obj):
- try:
- obj = int(obj) #if not a number, error
- if obj not in range(1,11):
- raise ValueError, "Not a valid choice" #if not 1 through 10, error
- return obj
- except ValueError:
- print "\nInvalid input!\n"
- os.system("pause")
- sys.exit(0)
- amount = levels[begin(choose)]
- else:
- amount = levels[lev]
- data = open(opened, "rb").read().encode("base64")
- blocksize = amount
- cuts = [data[i:i+blocksize] for i in range(0, len(data), blocksize)]
- for i in cuts:
- filename = str(hex(cuts.index(i)))+".txt"
- with open(filename,'wb') as out:
- out.write(i)
- out.close()
- compressor.compress(filename,filename) #compress the file (Reduces size about 30% usually)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement