OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 /** | 7 /** |
8 * Parser for MIME multipart types of data as described in RFC 2046 | 8 * Parser for MIME multipart types of data as described in RFC 2046 |
9 * section 5.1.1. The data to parse is supplied through the [:update:] | 9 * section 5.1.1. The data to parse is supplied through the [:update:] |
10 * method. As the data is parsed the following callbacks are called: | 10 * method. As the data is parsed the following callbacks are called: |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // current index. As the data can be artificially prefixed with a | 72 // current index. As the data can be artificially prefixed with a |
73 // prefix of the boundary both the content start index and index | 73 // prefix of the boundary both the content start index and index |
74 // can be negative. | 74 // can be negative. |
75 void reportData() { | 75 void reportData() { |
76 if (partDataReceived == null) return; | 76 if (partDataReceived == null) return; |
77 | 77 |
78 if (contentStartIndex < 0) { | 78 if (contentStartIndex < 0) { |
79 var contentLength = boundaryPrefix + index - _boundaryIndex; | 79 var contentLength = boundaryPrefix + index - _boundaryIndex; |
80 if (contentLength <= boundaryPrefix) { | 80 if (contentLength <= boundaryPrefix) { |
81 partDataReceived( | 81 partDataReceived( |
82 _boundary.getRange(0, contentLength)); | 82 _boundary.sublist(0, contentLength)); |
83 } else { | 83 } else { |
84 partDataReceived( | 84 partDataReceived( |
85 _boundary.getRange(0, boundaryPrefix)); | 85 _boundary.sublist(0, boundaryPrefix)); |
86 partDataReceived( | 86 partDataReceived( |
87 buffer.getRange(0, contentLength - boundaryPrefix)); | 87 buffer.sublist(0, contentLength - boundaryPrefix)); |
88 } | 88 } |
89 } else { | 89 } else { |
90 var contentLength = index - contentStartIndex - _boundaryIndex; | 90 var contentEndIndex = index - _boundaryIndex; |
91 partDataReceived( | 91 partDataReceived( |
92 buffer.getRange(contentStartIndex, contentLength)); | 92 buffer.sublist(contentStartIndex, contentEndIndex)); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 // Prepare for processing the buffer. | 96 // Prepare for processing the buffer. |
97 index = offset; | 97 index = offset; |
98 int lastIndex = offset + count; | 98 int lastIndex = offset + count; |
99 if (_state == _CONTENT && _boundaryIndex == 0) { | 99 if (_state == _CONTENT && _boundaryIndex == 0) { |
100 contentStartIndex = 0; | 100 contentStartIndex = 0; |
101 } else { | 101 } else { |
102 contentStartIndex = null; | 102 contentStartIndex = null; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 Function partDataReceived; | 324 Function partDataReceived; |
325 Function partEnd; | 325 Function partEnd; |
326 } | 326 } |
327 | 327 |
328 | 328 |
329 class MimeParserException implements Exception { | 329 class MimeParserException implements Exception { |
330 const MimeParserException([String this.message = ""]); | 330 const MimeParserException([String this.message = ""]); |
331 String toString() => "MimeParserException: $message"; | 331 String toString() => "MimeParserException: $message"; |
332 final String message; | 332 final String message; |
333 } | 333 } |
OLD | NEW |