<commit_before>import Foundation

// MARK: Data

extension Data: NodeRepresentable {
    public func makeNode(context: Context = EmptyNode) throws -> Node {
        let js = try JSONSerialization.jsonObject(with: self, options: .allowFragments)
        return Node(any: js)
    }
}

extension Data: NodeConvertible {
    public init(node: Node, in context: Context) throws {
        let any = node.any
        let data = try JSONSerialization.data(withJSONObject: any, options: .init(rawValue: 0))
        self = data
    }
}

// MARK: NSData

extension NSData: NodeRepresentable {
    public func makeNode(context: Context = EmptyNode) throws -> Node {
        var bytes = [UInt8](repeating: 0, count: length)
        getBytes(&bytes, length: bytes.count)
        let data = Data(bytes: bytes)
        let js = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
        return Node(any: js)
    }
}


#if Xcode
/*
Linux won't compile this.
*/
extension NSData: NodeConvertible {}
extension NodeConvertible where Self: NSData {
    public init(node: Node, in context: Context) throws {
        let any = node.any
        let data = try JSONSerialization.data(withJSONObject: any, options: .init(rawValue: 0))
        self.init(data: data)
    }
}
#endif
<commit_msg>Fix Foundation extensions<commit_after>import Foundation

// MARK: Data

extension Data: NodeRepresentable {
    public func makeNode(context: Context = EmptyNode) throws -> Node {
        let js = try JSONSerialization.jsonObject(with: self, options: .allowFragments)
        return Node(any: js)
    }
}

extension Data: NodeInitializable {
    public init(node: Node, in context: Context) throws {
        let any = node.any
        let data = try JSONSerialization.data(withJSONObject: any, options: [])
        self = data
    }
}

// MARK: NSData

extension NSData: NodeRepresentable {
    public func makeNode(context: Context = EmptyNode) throws -> Node {
        var bytes = [UInt8](repeating: 0, count: length)
        getBytes(&bytes, length: bytes.count)
        let data = Data(bytes: bytes)
        let js = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
        return Node(any: js)
    }
}


#if Xcode
/*
Linux won't compile this.
*/
extension NSData: NodeInitializable {}
extension NodeInitializable where Self: NSData {
    public init(node: Node, in context: Context) throws {
        let any = node.any
        let data = try JSONSerialization.data(withJSONObject: any, options: [])
        self.init(data: data)
    }
}
#endif

{'fraction_non_alphanumeric': 0.10242376856919469, 'fraction_numerical': 0.0023455824863174357, 'mean_word_length': 3.068362480127186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6527910', 'n_tokens_mistral': 761, 'n_tokens_neox': 746, 'n_words': 232}