API Reference 1.0.1+1rikulo_io

rikulo_io library

Functions

ContentType parseContentType(String value) #

Returns an instance of ContentType of the given value, such as text/html; charset=utf-8.

For example,

response.headers.contentType =
  parseContentType('text/html; charset=utf-8');

It is the same as ContentType.parse, except it will look for ContentType from those cached by getContentType. If not found, forward to ContentType.parse. Thus, the performance is little better.

ContentType parseContentType(String value) {
 final ContentType ctype = _rawCtypes[value];
 return ctype != null ? ctype: ContentType.parse(value);
}

ContentType getContentType(String extension) #

Returns ContentType of the specified extension, or null if not fund.

For example,

getContentType("js");
  //returns ContentType.parse("text/javascript; charset=utf-8")''

Notice: as shown, if the format is text (such as "text/plain" and "text/css"), the encoding is default to UTF8 (i.e., charset=utf-8 will be appended).

ContentType getContentType(String extension) {
 ContentType ctype = _ctypes[extension];
 if (ctype != null)
   return ctype;

 String mime = lookupMimeType(".$extension");
 if (mime == null)
   return null;

 if (_isTextType(mime))
   mime = "$mime; charset=utf-8";
 return _ctypes[extension] = _rawCtypes[mime] = ContentType.parse(mime);
}

String ungzipString(List<int> bytes, {Encoding encoding: UTF8}) #

Inflates a GIZP-ed string back to the original string.

String ungzipString(List<int> bytes, {Encoding encoding: UTF8})
=> encoding.decode(ungzip(bytes));

List<int> ungzip(List<int> bytes) #

Inflates a GZIP-ed list of bytes back to the original list of bytes.

List<int> ungzip(List<int> bytes) {
 final output = [];
 var error;
 var controller = new StreamController(sync: true);
 controller.stream
   .transform(new ZLibDecoder())
   .listen((data) => output.addAll(data),
     onError: (e) => error = e);
 controller.add(bytes);
 controller.close();
 if (error != null) throw error;
 return output; //note: it is done synchronously
}

List<int> gzipString(String string, {Encoding encoding: UTF8, int level: 6}) #

Deflates a String into a list of bytes with GZIP.

List<int> gzipString(String string, {Encoding encoding: UTF8, int level: 6})
=> gzip(encoding.encode(string), level: level);

List<int> gzip(List<int> bytes, {int level: 6}) #

Deflates a list of bytes with GZIP.

List<int> gzip(List<int> bytes, {int level: 6}) {
 final output = [];
 var error;
 var controller = new StreamController(sync: true);
 controller.stream
   .transform(new ZLibEncoder(level: level))
   .listen((data) => output.addAll(data),
     onError: (e) => error = e);
 controller.add(bytes);
 controller.close();
 if (error != null) throw error;
 return output; //note: it is done synchronously
}

Classes