<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_sample(binary, payload, path, filename):
 # pragma: no cover """ This function writes a sample on file system. Args: binary (bool):
 True if it's a binary file payload: payload of sample, in base64 if it's a binary path (string):
 path of file filename (string):
 name of file hash_ (string):
 file hash """

    if not os.path.exists(path):
        os.makedirs(path)

    sample = os.path.join(path, filename)

    if binary:
        with open(sample, "wb") as f:
            f.write(base64.b64decode(payload))
    else:
        with open(sample, "w") as f:
            f.write(payload)