fastimage 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +7 -9
  3. data/lib/fastimage.rb +35 -19
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d875303daa1b28112147473975032f3f81208c96
4
- data.tar.gz: 3d89ef08e50f8aa11792de19776cb86daa85a98d
3
+ metadata.gz: 8e91d72ee9017341028e1a4e39335bcbe38fd430
4
+ data.tar.gz: 1967da0aa3c2814d4cf8451df75dff1c50bc2d98
5
5
  SHA512:
6
- metadata.gz: 8026c5b308cd35dee11005123318cd1d19ec73f9da625014cef529e0855d570d1ba67618ecf4d2433239f699f6d2e2dcd9fc639c7ca4effe9c10d330d4ce3cb4
7
- data.tar.gz: 871b33aaa246cd85b80bac5376826e941385d73c1f90e5b084b0977df7d441de39c3fe6661c681715cdf67fe24629795dec95eebb0456cafb6cd8e1b591cbdea
6
+ metadata.gz: 272713d7824e59ef0f049f503ecbb57cbb2f65bb1e3a756aed3830ffd5131fcb2943d06d090d9bfb82f3f99ca64f385d76debf5f3b121b3974b16be6b7aa1676
7
+ data.tar.gz: 390252f65f7d4770c00431de27f353835ec6d39ca2ed32be99337210daabc769e28d9823a24905b86f8f557c63edc0502cff5a1c34aaee25e004316bc3efda2c
data/README.textile CHANGED
@@ -19,29 +19,27 @@ You only need supply the uri, and FastImage will do the rest.
19
19
 
20
20
  h2. Features
21
21
 
22
- Fastimage can also read local (and other) files - anything that is not parseable as a URI will be
23
- interpreted as a filename, and FastImage will attempt to open it with File#open.
22
+ FastImage can also read local (and other) files - anything that is not parseable as a URI will be interpreted as a filename, and FastImage will attempt to open it with @File#open@.
24
23
 
25
- FastImage will also automatically read from any object that responds to :read - for
26
- instance an IO object if that is passed instead of a URI.
24
+ FastImage will also automatically read from any object that responds to @:read@ - for instance an IO object if that is passed instead of a URI.
27
25
 
28
26
  FastImage will follow up to 4 HTTP redirects to get the image.
29
27
 
30
- FastImage will obey the http_proxy setting in your environment to route requests via a proxy. You can also pass a :proxy argument if you want to specify the proxy address in the call.
28
+ FastImage will obey the @http_proxy@ setting in your environment to route requests via a proxy. You can also pass a @:proxy@ argument if you want to specify the proxy address in the call.
31
29
 
32
- You can add a timeout to the request which will limit the request time by passing :timeout => number_of_seconds.
30
+ You can add a timeout to the request which will limit the request time by passing @:timeout => number_of_seconds@.
33
31
 
34
- FastImage normally replies will nil if it encounters an error, but you can pass :raise_on_failure => true to get an exception.
32
+ FastImage normally replies with @nil@ if it encounters an error, but you can pass @:raise_on_failure => true@ to get an exception.
35
33
 
36
34
  FastImage also provides a reader for the content length header provided in HTTP. This may be useful to assess the file size of an image, but do not rely on it exclusively - it will not be present in chunked responses for instance.
37
35
 
38
- FastImage accepts additional HTTP headers. This can be used to set a user agent or referrer which some servers require. Pass an :http_header argument to specify headers, e.g., :http_header => {'User-Agent' => 'Fake Browser'}.
36
+ FastImage accepts additional HTTP headers. This can be used to set a user agent or referrer which some servers require. Pass an @:http_header@ argument to specify headers, e.g., @:http_header => {'User-Agent' => 'Fake Browser'}@.
39
37
 
40
38
  FastImage can give you information about the parsed display orientation of an image with Exif data (jpeg or tiff).
41
39
 
42
40
  h2. Security
43
41
 
44
- As of v1.6.7 FastImage no longer uses openuri to open files, but directly calls File.open. But take care to sanitise the strings passed to FastImage; it will try to read from whatever is passed.
42
+ As of v1.6.7 FastImage no longer uses @openuri@ to open files, but directly calls @File.open@. Take care to sanitise the strings passed to FastImage; it will try to read from whatever is passed.
45
43
 
46
44
  h2. Examples
47
45
 
data/lib/fastimage.rb CHANGED
@@ -417,6 +417,24 @@ class FastImage
417
417
  @pos += n
418
418
  result
419
419
  end
420
+
421
+ def skip(n)
422
+ discarded = 0
423
+ fetched = @str[@strpos..-1].size
424
+ while n > fetched
425
+ discarded += @str[@strpos..-1].size
426
+ new_string = @read_fiber.resume
427
+ raise CannotParseImage if !new_string
428
+
429
+ new_string.force_encoding("ASCII-8BIT") if String.method_defined? :force_encoding
430
+
431
+ fetched += new_string.size
432
+ @str = new_string
433
+ @strpos = 0
434
+ end
435
+ @strpos = @strpos + n - discarded
436
+ @pos += n
437
+ end
420
438
  end
421
439
 
422
440
  class IOStream < SimpleDelegator # :nodoc:
@@ -424,7 +442,7 @@ class FastImage
424
442
  end
425
443
 
426
444
  def parse_type
427
- case @stream.peek(2)
445
+ parsed_type = case @stream.peek(2)
428
446
  when "BM"
429
447
  :bmp
430
448
  when "GI"
@@ -444,26 +462,20 @@ class FastImage
444
462
  when 2 then :cur
445
463
  end
446
464
  when "RI"
447
- if @stream.peek(12)[8..11] == "WEBP"
448
- :webp
449
- else
450
- raise UnknownImageType
451
- end
465
+ :webp if @stream.peek(12)[8..11] == "WEBP"
452
466
  when "<s"
453
467
  :svg
454
468
  when "<?"
455
- if @stream.peek(100).include?("<svg")
456
- :svg
457
- else
458
- raise UnknownImageType
459
- end
460
- else
461
- raise UnknownImageType
469
+ :svg if @stream.peek(100).include?("<svg")
462
470
  end
471
+
472
+ parsed_type or raise UnknownImageType
463
473
  end
464
474
 
465
475
  def parse_size_for_ico
466
- @stream.read(8)[6..7].unpack('CC').map{|byte| byte == 0 ? 256 : byte }
476
+ icons = @stream.read(6)[4..5].unpack('v').first
477
+ sizes = icons.times.map { @stream.read(16).unpack('C2').map { |x| x == 0 ? 256 : x } }.sort_by { |w,h| w * h }
478
+ sizes.last
467
479
  end
468
480
  alias_method :parse_size_for_cur, :parse_size_for_ico
469
481
 
@@ -479,7 +491,7 @@ class FastImage
479
491
  loop do
480
492
  @state = case @state
481
493
  when nil
482
- @stream.read(2)
494
+ @stream.skip(2)
483
495
  :started
484
496
  when :started
485
497
  @stream.read_byte == 0xFF ? :sof : :started
@@ -505,10 +517,10 @@ class FastImage
505
517
  end
506
518
  when :skipframe
507
519
  skip_chars = @stream.read_int - 2
508
- @stream.read(skip_chars)
520
+ @stream.skip(skip_chars)
509
521
  :started
510
522
  when :readsize
511
- s = @stream.read(3)
523
+ @stream.skip(3)
512
524
  height = @stream.read_int
513
525
  width = @stream.read_int
514
526
  width, height = height, width if @exif && @exif.rotated?
@@ -552,7 +564,7 @@ class FastImage
552
564
  end
553
565
 
554
566
  def parse_size_vp8l
555
- @stream.read(1) # 0x2f
567
+ @stream.skip(1) # 0x2f
556
568
  b1, b2, b3, b4 = @stream.read(4).bytes.to_a
557
569
  [1 + (((b2 & 0x3f) << 8) | b1), 1 + (((b4 & 0xF) << 10) | (b3 << 2) | ((b2 & 0xC0) >> 6))]
558
570
  end
@@ -625,7 +637,11 @@ class FastImage
625
637
  @stream.read(2) # 42
626
638
 
627
639
  offset = @stream.read(4).unpack(@long)[0]
628
- @stream.read(offset - 8)
640
+ if @stream.respond_to?(:skip)
641
+ @stream.skip(offset - 8)
642
+ else
643
+ @stream.read(offset - 8)
644
+ end
629
645
 
630
646
  parse_exif_ifd
631
647
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Sykes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable