FIRStoragePath.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * Represents a path in GCS, which can be represented as: gs://bucket/path/to/object
  20. * or http[s]://firebasestorage.googleapis.com/v0/b/bucket/o/path/to/object?token=<12345>
  21. * This class also includes helper methods to parse those URI/Ls, as well as to
  22. * add and remove path segments.
  23. */
  24. @interface FIRStoragePath : NSObject
  25. /**
  26. * The GCS bucket in the path.
  27. */
  28. @property(copy, nonatomic) NSString *bucket;
  29. /**
  30. * The GCS object in the path.
  31. */
  32. @property(copy, nonatomic, nullable) NSString *object;
  33. /**
  34. * Parses a generic string (representing some URI or URL) and returns the appropriate path.
  35. * @param string String which is parsed into a path.
  36. * @return Returns an instance of FIRStoragePath or nil if one can't be created.
  37. * @throws Throws an exception if the string is not a valid gs:// URI or http[s]:// URL.
  38. */
  39. + (nullable FIRStoragePath *)pathFromString:(NSString *)string;
  40. /**
  41. * Parses a gs://bucket/path/to/object URI into a GCS path.
  42. * @param aURIString gs:// URI which is parsed into a path.
  43. * @return Returns an instance of FIRStoragePath or nil if one can't be created.
  44. * @throws Throws an exception if the string is not a valid gs:// URI.
  45. */
  46. + (nullable FIRStoragePath *)pathFromGSURI:(NSString *)aURIString;
  47. - (instancetype)init NS_UNAVAILABLE;
  48. /**
  49. * Constructs an FIRStoragePath object that represents the given bucket and object.
  50. * @param bucket The name of the bucket.
  51. * @param object The name of the object.
  52. * @return An instance of FIRStoragePath representing the @a bucket and @a object.
  53. */
  54. - (instancetype)initWithBucket:(NSString *)bucket
  55. object:(nullable NSString *)object NS_DESIGNATED_INITIALIZER;
  56. /**
  57. * Parses a http[s]://firebasestorage.googleapis.com/v0/b/bucket/o/path/to/object...?token=<12345>
  58. * URL into a GCS path.
  59. * @param aURLString http[s]:// URL which is parsed into a path.
  60. * string which is parsed into a path.
  61. * @return Returns an instance of FIRStoragePath or nil if one can't be created.
  62. * @throws Throws an exception if the string is not a valid http[s]:// URL.
  63. */
  64. + (nullable FIRStoragePath *)pathFromHTTPURL:(NSString *)aURLString;
  65. /**
  66. * Creates a new path based off of the current path and a string appended to it.
  67. * Note that all slashes are compressed to a single slash, and leading and trailing slashes
  68. * are removed.
  69. * @param path String to append to the current path.
  70. * @return Returns a new instance of FIRStoragePath with the new path appended.
  71. */
  72. - (FIRStoragePath *)child:(NSString *)path;
  73. /**
  74. * Creates a new path based off of the current path with the last path segment removed.
  75. * @return Returns a new instance of FIRStoragePath pointing to the parent path,
  76. * or nil if the current path points to the root.
  77. */
  78. - (nullable FIRStoragePath *)parent;
  79. /**
  80. * Creates a new path based off of the root of the bucket.
  81. * @return Returns a new instance of FIRStoragePath pointing to the root of the bucket.
  82. */
  83. - (FIRStoragePath *)root;
  84. /**
  85. * Returns a GS URI representing the current path.
  86. * @return Returns a gs://bucket/path/to/object URI representing the current path.
  87. */
  88. - (NSString *)stringValue;
  89. @end
  90. NS_ASSUME_NONNULL_END