<commit_before>import socket
import os, sys, time, threading, shutil, time
import Image
from packages.rmmedia import mediaplayer
from constants import *


def readInt(data):
    intBytes = data[:4]
    remainingData = data[4:]
    num = (intBytes[0] << 24) + (intBytes[1] << 16) + (intBytes[2] << 8) + intBytes[3]
    return num, remainingData

# added size!
def readString(data, size):
    #size, data = readInt(data)
    strBytes = data[:size]
    remainingData = data[size:]
    inStr = str(strBytes)
    return inStr, remainingData


def interpret(tmpFilePath):
    with open(tmpFilePath) as f:
        data = bytearray(f.read(4))
        numFiles, data = readInt(data)

        # check thumbnails path
        thumbsPath = os.getcwd() + '/media/thumbs/'
        if not os.path.isdir(thumbsPath):
            os.mkdir(thumbsPath)

        print "READING %d FILES" % numFiles
        for i in range(numFiles):
            # read file name
            data = bytearray(f.read(4))
            size, data = readInt(data)
            data = bytearray(f.read(size))
            name, data = readString(data, size)
            openPath = os.getcwd() + '/media/' + name
            data = bytearray(f.read(4))
            fileSize, data = readInt(data)
            if not os.path.isdir(openPath):
                f = open(openPath, 'w+') #open in binary
                l = f.read(fileSize)
                #l = data[:fileSize]<commit_msg>Temp file processing switching to byte mode, testing.<commit_after>import socket
import os, sys, time, threading, shutil, time
import Image
from packages.rmmedia import mediaplayer
from constants import *


def readInt(data):
    intBytes = data[:4]
    remainingData = data[4:]
    num = (intBytes[0] << 24) + (intBytes[1] << 16) + (intBytes[2] << 8) + intBytes[3]
    return num, remainingData

# added size!
def readString(data, size):
    #size, data = readInt(data)
    strBytes = data[:size]
    remainingData = data[size:]
    inStr = str(strBytes)
    return inStr, remainingData


def interpret(tmpFilePath):
    # open temp file in binary mode
    with open(tmpFilePath, 'w+') as f:
        data = bytearray(f.read(4))
        numFiles, data = readInt(data)

        # check thumbnails path
        thumbsPath = os.getcwd() + '/media/thumbs/'
        if not os.path.isdir(thumbsPath):
            os.mkdir(thumbsPath)

        print "READING %d FILES" % numFiles
        for i in range(numFiles):
            # read file name
            data = bytearray(f.read(4))
            size, data = readInt(data)
            data = bytearray(f.read(size))
            name, data = readString(data, size)
            openPath = os.getcwd() + '/media/' + name
            data = bytearray(f.read(4))
            fileSize, data = readInt(data)
            if not os.path.isdir(openPath):
                f = open(openPath, 'w+') #open in binary
                l = f.read(fileSize)
                #l = data[:fileSize]
{'fraction_non_alphanumeric': 0.1209349593495935, 'fraction_numerical': 0.009485094850948509, 'mean_word_length': 2.277469478357381, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5315920', 'n_tokens_mistral': 947, 'n_tokens_neox': 918, 'n_words': 249}