1. Swift / Говнокод #25705

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    /* Create a JSON object from JSON data stream. The stream should be opened and configured. All other behavior of this method is the same as the JSONObjectWithData:options:error: method.
         */
    open class func jsonObject(with stream: InputStream, options opt: ReadingOptions = []) throws -> Any {
        var data = Data()
        guard stream.streamStatus == .open || stream.streamStatus == .reading else {
             fatalError("Stream is not available for reading")
         }
         repeat {
             var buffer = [UInt8](repeating: 0, count: 1024)
             var bytesRead: Int = 0
             bytesRead = stream.read(&buffer, maxLength: buffer.count)
             if bytesRead < 0 {
                 throw stream.streamError!
             } else {
                 data.append(&buffer, count: bytesRead)
             }
         } while stream.hasBytesAvailable
         return try jsonObject(with: data, options: opt)
    }

    Потоковое чтение JSON от авторов "iСделаль"

    Запостил: Desktop, 07 Июля 2019

    Комментарии (23) RSS

    Добавить комментарий