def close(self):
        """Add docstring!"""

        # Seek to the start of the buffer
        self.seek(0)
        while True:

            # Copy bytes from the buffer until we reach the end of the JSON
            brace_count = 0
            quoted = False
            json_string = ''
            while True:

                # Read a character
                b = self.read(1)
                if b == b'':
                    return
                c = b.decode()

                # If it is a \ then copy the next character
                if c == '\\':
                    json_string += c
                    json_string += self.read(1).decode()
                    continue

                # If we are inside quotes we just need to detect a
                # closing quote
                if c == '"':
                    if quoted:
                        quoted = False
                    else:
                        quoted = True

                # Otherwise we count the braces
                if c == '{':
                    brace_count += 1
                elif c == '}':
                    brace_count -= 1

                # Copy the character into the JSON string
                json_string += c

                # If the brace count is zero we are done
                if brace_count == 0:
                    break

            # Parse the JSON so that we can get the size of the data array
            meta = json.loads(json_string)
            n_channels = meta['data_cube']['n_channels']
            n_sub_integrations = meta['data_cube']['n_sub_integrations']

            # Save the JSON to a file
            f = open('{0}_{1}_{2}.json'.format(
                meta['metadata']['observation_id'],
                meta['metadata']['beam_id'],
                meta['metadata']['name']), 'w')

            f.write(json.dumps(meta))
            f.close()

            # Read the data
            data = self.read(n_channels * n_sub_integrations)

            # Write it to a file
            f = open('{0}_{1}_{2}.data'.format(
                meta['metadata']['observation_id'],
                meta['metadata']['beam_id'],
                meta['metadata']['name']), 'wb')
            f.write(data)
            f.close()