{
  "schema": "https://ai-atoms.com/schemas/skill-v1.json",
  "type": "skill",
  "id": "skill/azure-storage-file-share-ts",
  "version": "1.0.1",
  "name": "Azure Storage File Share Ts",
  "description": "Azure File Share JavaScript/TypeScript SDK (@azure/storage-file-share) for SMB file share operations. Use for creating shares, managing directories, uploading/downloading files, and handling file metadata. Supports Azure Files SMB protocol scenarios. Triggers: \"file share\", \"@azure/storage-file-share\", \"ShareServiceClient\", \"ShareClient\", \"SMB\", \"Azure Files\".",
  "system_prompt_fragment": "# @azure/storage-file-share (TypeScript/JavaScript)\n\nSDK for Azure File Share operations — SMB file shares, directories, and file operations.\n\n## Installation\n\n```bash\nnpm install @azure/storage-file-share @azure/identity\n```\n\n**Current Version**: 12.x  \n**Node.js**: >= 18.0.0\n\n## Environment Variables\n\n```bash\nAZURE_STORAGE_ACCOUNT_NAME=<account-name>\nAZURE_STORAGE_ACCOUNT_KEY=<account-key>\n# OR connection string\nAZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=...\n```\n\n## Authentication\n\n### Connection String (Simplest)\n\n```typescript\nimport { ShareServiceClient } from \"@azure/storage-file-share\";\n\nconst client = ShareServiceClient.fromConnectionString(\n  process.env.AZURE_STORAGE_CONNECTION_STRING!\n);\n```\n\n### StorageSharedKeyCredential (Node.js only)\n\n```typescript\nimport { ShareServiceClient, StorageSharedKeyCredential } from \"@azure/storage-file-share\";\n\nconst accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME!;\nconst accountKey = process.env.AZURE_STORAGE_ACCOUNT_KEY!;\n\nconst sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);\nconst client = new ShareServiceClient(\n  `https://${accountName}.file.core.windows.net`,\n  sharedKeyCredential\n);\n```\n\n### DefaultAzureCredential\n\n```typescript\nimport { ShareServiceClient } from \"@azure/storage-file-share\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME!;\nconst client = new ShareServiceClient(\n  `https://${accountName}.file.core.windows.net`,\n  new DefaultAzureCredential()\n);\n```\n\n### SAS Token\n\n```typescript\nimport { ShareServiceClient } from \"@azure/storage-file-share\";\n\nconst accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME!;\nconst sasToken = process.env.AZURE_STORAGE_SAS_TOKEN!;\n\nconst client = new ShareServiceClient(\n  `https://${accountName}.file.core.windows.net${sasToken}`\n);\n```\n\n## Client Hierarchy\n\n```\nShareServiceClient (account level)\n└── ShareClient (share level)\n    └── ShareDirectoryClient (directory level)\n        └── ShareFileClient (file level)\n```\n\n## Share Operations\n\n### Create Share\n\n```typescript\nconst shareClient = client.getShareClient(\"my-share\");\nawait shareClient.create();\n\n// Create with quota (in GB)\nawait shareClient.create({ quota: 100 });\n```\n\n### List Shares\n\n```typescript\nfor await (const share of client.listShares()) {\n  console.log(share.name, share.properties.quota);\n}\n\n// With prefix filter\nfor await (const share of client.listShares({ prefix: \"logs-\" })) {\n  console.log(share.name);\n}\n```\n\n### Delete Share\n\n```typescript\nawait shareClient.delete();\n\n// Delete if exists\nawait shareClient.deleteIfExists();\n```\n\n### Get Share Properties\n\n```typescript\nconst properties = await shareClient.getProperties();\nconsole.log(\"Quota:\", properties.quota, \"GB\");\nconsole.log(\"Last Modified:\", properties.lastModified);\n```\n\n### Set Share Quota\n\n```typescript\nawait shareClient.setQuota(200); // 200 GB\n```\n\n## Directory Operations\n\n### Create Directory\n\n```typescript\nconst directoryClient = shareClient.getDirectoryClient(\"my-directory\");\nawait directoryClient.create();\n\n// Create nested directory\nconst nestedDir = shareClient.getDirectoryClient(\"parent/child/grandchild\");\nawait nestedDir.create();\n```\n\n### List Directories and Files\n\n```typescript\nconst directoryClient = shareClient.getDirectoryClient(\"my-directory\");\n\nfor await (const item of directoryClient.listFilesAndDirectories()) {\n  if (item.kind === \"directory\") {\n    console.log(`[DIR] ${item.name}`);\n  } else {\n    console.log(`[FILE] ${item.name} (${item.properties.contentLength} bytes)`);\n  }\n}\n```\n\n### Delete Directory\n\n```typescript\nawait directoryClient.delete();\n\n// Delete if exists\nawait directoryClient.deleteIfExists();\n```\n\n### Check if Directory Exists\n\n```typescript\nconst exists = await directoryClient.exists();\nif (!exists) {\n  await directoryClient.create();\n}\n```\n\n## File Operations\n\n### Upload File (Simple)\n\n```typescript\nconst fileClient = shareClient\n  .getDirectoryClient(\"my-directory\")\n  .getFileClient(\"my-file.txt\");\n\n// Upload string\nconst content = \"Hello, World!\";\nawait fileClient.create(content.length);\nawait fileClient.uploadRange(content, 0, content.length);\n```\n\n### Upload File (Node.js - from local file)\n\n```typescript\nimport * as fs from \"fs\";\nimport * as path from \"path\";\n\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"uploaded.txt\");\nconst localFilePath = \"/path/to/local/file.txt\";\nconst fileSize = fs.statSync(localFilePath).size;\n\nawait fileClient.create(fileSize);\nawait fileClient.uploadFile(localFilePath);\n```\n\n### Upload File (Buffer)\n\n```typescript\nconst buffer = Buffer.from(\"Hello, Azure Files!\");\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"buffer-file.txt\");\n\nawait fileClient.create(buffer.length);\nawait fileClient.uploadRange(buffer, 0, buffer.length);\n```\n\n### Upload File (Stream)\n\n```typescript\nimport * as fs from \"fs\";\n\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"streamed.txt\");\nconst readStream = fs.createReadStream(\"/path/to/local/file.txt\");\nconst fileSize = fs.statSync(\"/path/to/local/file.txt\").size;\n\nawait fileClient.create(fileSize);\nawait fileClient.uploadStream(readStream, fileSize, 4 * 1024 * 1024, 4); // 4MB buffer, 4 concurrency\n```\n\n### Download File\n\n```typescript\nconst fileClient = shareClient\n  .getDirectoryClient(\"my-directory\")\n  .getFileClient(\"my-file.txt\");\n\nconst downloadResponse = await fileClient.download();\n\n// Read as string\nconst chunks: Buffer[] = [];\nfor await (const chunk of downloadResponse.readableStreamBody!) {\n  chunks.push(Buffer.from(chunk));\n}\nconst content = Buffer.concat(chunks).toString(\"utf-8\");\n```\n\n### Download to File (Node.js)\n\n```typescript\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"my-file.txt\");\nawait fileClient.downloadToFile(\"/path/to/local/destination.txt\");\n```\n\n### Download to Buffer (Node.js)\n\n```typescript\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"my-file.txt\");\nconst buffer = await fileClient.downloadToBuffer();\nconsole.log(buffer.toString());\n```\n\n### Delete File\n\n```typescript\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"my-file.txt\");\nawait fileClient.delete();\n\n// Delete if exists\nawait fileClient.deleteIfExists();\n```\n\n### Copy File\n\n```typescript\nconst sourceUrl = \"https://account.file.core.windows.net/share/source.txt\";\nconst destFileClient = shareClient.rootDirectoryClient.getFileClient(\"destination.txt\");\n\n// Start copy operation\nconst copyPoller = await destFileClient.startCopyFromURL(sourceUrl);\nawait copyPoller.pollUntilDone();\n```\n\n## File Properties & Metadata\n\n### Get File Properties\n\n```typescript\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"my-file.txt\");\nconst properties = await fileClient.getProperties();\n\nconsole.log(\"Content-Length:\", properties.contentLength);\nconsole.log(\"Content-Type:\", properties.contentType);\nconsole.log(\"Last Modified:\", properties.lastModified);\nconsole.log(\"ETag:\", properties.etag);\n```\n\n### Set Metadata\n\n```typescript\nawait fileClient.setMetadata({\n  author: \"John Doe\",\n  category: \"documents\",\n});\n```\n\n### Set HTTP Headers\n\n```typescript\nawait fileClient.setHttpHeaders({\n  fileContentType: \"text/plain\",\n  fileCacheControl: \"max-age=3600\",\n  fileContentDisposition: \"attachment; filename=download.txt\",\n});\n```\n\n## Range Operations\n\n### Upload Range\n\n```typescript\nconst data = Buffer.from(\"partial content\");\nawait fileClient.uploadRange(data, 100, data.length); // Write at offset 100\n```\n\n### Download Range\n\n```typescript\nconst downloadResponse = await fileClient.download(100, 50); // offset 100, length 50\n```\n\n### Clear Range\n\n```typescript\nawait fileClient.clearRange(0, 100); // Clear first 100 bytes\n```\n\n## Snapshot Operations\n\n### Create Snapshot\n\n```typescript\nconst snapshotResponse = await shareClient.createSnapshot();\nconsole.log(\"Snapshot:\", snapshotResponse.snapshot);\n```\n\n### Access Snapshot\n\n```typescript\nconst snapshotShareClient = shareClient.withSnapshot(snapshotResponse.snapshot!);\nconst snapshotFileClient = snapshotShareClient.rootDirectoryClient.getFileClient(\"file.txt\");\nconst content = await snapshotFileClient.downloadToBuffer();\n```\n\n### Delete Snapshot\n\n```typescript\nawait shareClient.delete({ deleteSnapshots: \"include\" });\n```\n\n## SAS Token Generation (Node.js only)\n\n### Generate File SAS\n\n```typescript\nimport {\n  generateFileSASQueryParameters,\n  FileSASPermissions,\n  StorageSharedKeyCredential,\n} from \"@azure/storage-file-share\";\n\nconst sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);\n\nconst sasToken = generateFileSASQueryParameters(\n  {\n    shareName: \"my-share\",\n    filePath: \"my-directory/my-file.txt\",\n    permissions: FileSASPermissions.parse(\"r\"), // read only\n    expiresOn: new Date(Date.now() + 3600 * 1000), // 1 hour\n  },\n  sharedKeyCredential\n).toString();\n\nconst sasUrl = `https://${accountName}.file.core.windows.net/my-share/my-directory/my-file.txt?${sasToken}`;\n```\n\n### Generate Share SAS\n\n```typescript\nimport { ShareSASPermissions, generateFileSASQueryParameters } from \"@azure/storage-file-share\";\n\nconst sasToken = generateFileSASQueryParameters(\n  {\n    shareName: \"my-share\",\n    permissions: ShareSASPermissions.parse(\"rcwdl\"), // read, create, write, delete, list\n    expiresOn: new Date(Date.now() + 24 * 3600 * 1000), // 24 hours\n  },\n  sharedKeyCredential\n).toString();\n```\n\n## Error Handling\n\n```typescript\nimport { RestError } from \"@azure/storage-file-share\";\n\ntry {\n  await shareClient.create();\n} catch (error) {\n  if (error instanceof RestError) {\n    switch (error.statusCode) {\n      case 404:\n        console.log(\"Share not found\");\n        break;\n      case 409:\n        console.log(\"Share already exists\");\n        break;\n      case 403:\n        console.log(\"Access denied\");\n        break;\n      default:\n        console.error(`Storage error ${error.statusCode}: ${error.message}`);\n    }\n  }\n  throw error;\n}\n```\n\n## TypeScript Types Reference\n\n```typescript\nimport {\n  // Clients\n  ShareServiceClient,\n  ShareClient,\n  ShareDirectoryClient,\n  ShareFileClient,\n\n  // Authentication\n  StorageSharedKeyCredential,\n  AnonymousCredential,\n\n  // SAS\n  FileSASPermissions,\n  ShareSASPermissions,\n  AccountSASPermissions,\n  AccountSASServices,\n  AccountSASResourceTypes,\n  generateFileSASQueryParameters,\n  generateAccountSASQueryParameters,\n\n  // Options & Responses\n  ShareCreateResponse,\n  FileDownloadResponseModel,\n  DirectoryItem,\n  FileItem,\n  ShareProperties,\n  FileProperties,\n\n  // Errors\n  RestError,\n} from \"@azure/storage-file-share\";\n```\n\n## Best Practices\n\n1. **Use connection strings for simplicity** — Easiest setup for development\n2. **Use DefaultAzureCredential for production** — Enable managed identity in Azure\n3. **Set quotas on shares** — Prevent unexpected storage costs\n4. **Use streaming for large files** — `uploadStream`/`downloadToFile` for files > 256MB\n5. **Use ranges for partial updates** — More efficient than full file replacement\n6. **Create snapshots before major changes** — Point-in-time recovery\n7. **Handle errors gracefully** — Check `RestError.statusCode` for specific handling\n8. **Use `*IfExists` methods** — For idempotent operations\n\n## Platform Differences\n\n| Feature | Node.js | Browser |\n|---------|---------|---------|\n| `StorageSharedKeyCredential` | ✅ | ❌ |\n| `uploadFile()` | ✅ | ❌ |\n| `uploadStream()` | ✅ | ❌ |\n| `downloadToFile()` | ✅ | ❌ |\n| `downloadToBuffer()` | ✅ | ❌ |\n| SAS generation | ✅ | ❌ |\n| DefaultAzureCredential | ✅ | ❌ |\n| Anonymous/SAS access | ✅ | ✅ |\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.",
  "applicable_domains": [
    "devops"
  ],
  "category": "devops",
  "invocation": [
    "/azure-storage-file-share-ts"
  ],
  "authored_by": "claudeskills.in community",
  "source_url": "https://claudeskills.in/skill/azure-storage-file-share-ts",
  "provenance": {
    "source": "claudeskills.in",
    "source_url": "https://claudeskills.in/skill/azure-storage-file-share-ts",
    "license": "unknown",
    "imported_at": "2026-09-03",
    "notes": "Aggregated by claudeskills.in from community GitHub lists."
  },
  "tags": [
    "claudeskills",
    "devops"
  ],
  "lifecycle": "draft"
}