Revisions
-
mattiasostmar revised this gist
Dec 10, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,6 @@ def joinFiles(fileName,noOfChunks,chunkSize): dataList.append(f.read()) f.close() for data in dataList: f2 = open(fileName, 'wb') f2.write(data) f2.close() -
mattiasostmar revised this gist
Dec 10, 2013 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,8 +41,7 @@ def joinFiles(fileName,noOfChunks,chunkSize): f = open(chunkName, 'rb') dataList.append(f.read()) f.close() for data in dataList: f2 = open(fileName, 'wb') f2.write(data) f2.close() -
mattiasostmar created this gist
Dec 10, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ # define the function to split the file into smaller chunks def splitFile(inputFile,chunkSize): #read the contents of the file f = open(inputFile, 'rb') data = f.read() f.close() # get the length of data, ie size of the input file in bytes bytes = len(data) #calculate the number of chunks to be created noOfChunks= bytes/chunkSize if(bytes%chunkSize): noOfChunks+=1 #create a info.txt file for writing metadata f = open('info.txt', 'w') f.write(inputFile+','+'chunk,'+str(noOfChunks)+','+str(chunkSize)) f.close() chunkNames = [] for i in range(0, bytes+1, chunkSize): fn1 = "chunk%s" % i chunkNames.append(fn1) f = open(fn1, 'wb') f.write(data[i:i+ chunkSize]) f.close() #define the function to join the chunks of files into a single file def joinFiles(fileName,noOfChunks,chunkSize): dataList = [] for i in range(0,noOfChunks,1): chunkNum=i * chunkSize chunkName = fileName+'%s'%chunkNum f = open(chunkName, 'rb') dataList.append(f.read()) f.close() #Alteration: I open the files as f2 within the loop. for data in dataList: f2 = open(fileName, 'wb') f2.write(data) f2.close()