-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chunked_files.py
47 lines (39 loc) · 1.22 KB
/
Chunked_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def partition(filename,NumberofChunks):
#opening file as read binary - bytearray
with open(filename,'rb') as fls:
f = fls.read()
b = bytearray(f)
fls.close()
wordlength = len(b)
#Predicting size of each piece
size = int(wordlength/NumberofChunks)
#Making Chunks names
for i in range(0,NumberofChunks):
chunkNames.append("filename"+str(i))
#Making chunks
start = 0
end = size
for i in range(0,NumberofChunks):
arrayDict[i] = b[start:end]
start += size
end += size
#chunk1 = b[0: size]
#chunk2 = b[int(wordlength/NumberofChunks) :int(wordlength)]
chunkNames = [] #chunkName list
arrayDict = [] #array dictionary
# # Used Generator to generate chunk names
# def chunkNames():
# for i in range(1, NumberofChunks):
# yield + str(i)
#writing chunk bytearray to chunked files
def ChunkWrite(Numberofchunks,ext):
for i in range(0, Numberofchunks):
chunk = open(chunkNames[i]+'.'+ext,'wb')
chunk.write(bytearray(arrayDict[i]))
chunk.close()
#k = open('test1.mp4','wb')
#k.write(bytearray(chunk1))
#k.close()
#j = open('test2.mp4','wb')
#j.write(bytearray(chunk2))
#j.close()